Day.js Oyun Alanı ve Biçim Başvurusu
- Dosyalar cihazınızdan çıkmaz
- Tarayıcıda çalışır
- Ücretsiz, kayıt yok, filigran yok
Format playground
Format tokens
Click a token to insert it into the format string. Examples use the reference date and locale.
| Token | Example | Meaning | Day.js |
|---|---|---|---|
| Year and quarter | |||
| Four-digit year | core | ||
| Two-digit year | core | ||
| Quarter (1–4) | advancedFormat | ||
| not in Day.js | Quarter, ordinal | not in Day.js | |
| Month | |||
| Month (1–12) | core | ||
| not in Day.js | Month, ordinal | not in Day.js | |
| Month, two digits | core | ||
| Month, short name | core | ||
| Month, full name | core | ||
| Day of month and year | |||
| Day of month | core | ||
| Day of month, ordinal | advancedFormat | ||
| Day of month, two digits | core | ||
| not in Day.js | Day of year | not in Day.js | |
| not in Day.js | Day of year, three digits | not in Day.js | |
| Day of week | |||
| Day of week (0 = Sunday) | core | ||
| Weekday, shortest name | core | ||
| Weekday, short name | core | ||
| Weekday, full name | core | ||
| not in Day.js | Day of week, by locale | not in Day.js | |
| not in Day.js | ISO day of week (1 = Monday) | not in Day.js | |
| Week | |||
| Week of year, by locale | advancedFormat + weekOfYear | ||
| Week of year, ordinal | advancedFormat + weekOfYear | ||
| Week of year, two digits | advancedFormat + weekOfYear | ||
| ISO week of year | advancedFormat + isoWeek | ||
| ISO week, two digits | advancedFormat + isoWeek | ||
| Week-numbering year, by locale | advancedFormat + weekYear | ||
| ISO week-numbering year | advancedFormat + isoWeek | ||
| Hour | |||
| Hour, 0–23 | core | ||
| Hour, 00–23 | core | ||
| Hour, 1–12 | core | ||
| Hour, 01–12 | core | ||
| Hour, 1–24 | advancedFormat | ||
| Hour, 01–24 | advancedFormat | ||
| Minute and second | |||
| Minute | core | ||
| Minute, two digits | core | ||
| Second | core | ||
| Second, two digits | core | ||
| not in Day.js | Tenths of a second | not in Day.js | |
| not in Day.js | Hundredths of a second | not in Day.js | |
| Milliseconds | core | ||
| AM / PM | |||
| AM / PM | core | ||
| am / pm | core | ||
| Time zone | |||
| UTC offset, ±HH:mm | core | ||
| UTC offset, ±HHmm | core | ||
| Time zone abbreviation | advancedFormat + timezone | ||
| Time zone name | advancedFormat + timezone | ||
| Unix time | |||
| Unix seconds | advancedFormat | ||
| Unix milliseconds | advancedFormat | ||
| Localized formats | |||
| Localized time | localizedFormat | ||
| Localized time with seconds | localizedFormat | ||
| Localized numeric date | localizedFormat | ||
| Localized date with month name | localizedFormat | ||
| Localized date and time | localizedFormat | ||
| Localized date and time with weekday | localizedFormat | ||
| Short numeric date | localizedFormat | ||
| Short date with month name | localizedFormat | ||
| Short date and time | localizedFormat | ||
| Short date and time with weekday | localizedFormat | ||
| Escaping | |||
| Text in square brackets is printed as is | core | ||
Parse playground
Leave empty to parse ISO 8601.
Relative time
Each row shifts the reference date, then describes it relative to the reference with from() and calendar().
| Shift | from(ref) | calendar(ref) |
|---|---|---|
| .add(-45, 'second') | ||
| .add(-10, 'minute') | ||
| .add(-3, 'hour') | ||
| .add(-1, 'day') | ||
| .add(-5, 'day') | ||
| .add(-3, 'month') | ||
| .add(-2, 'year') | ||
| .add(30, 'minute') | ||
| .add(2, 'day') | ||
| .add(1, 'month') |
Durations
Recipes
Everyday tasks with live results. “Try” loads one into the code runner below.
| Task | Day.js |
|---|---|
Format the current time | dayjs().format('YYYY-MM-DD HH:mm:ss')→ |
Add days | dayjs('2023-01-01').add(1, 'day').format('YYYY-MM-DD')→ |
Time from now Day.js: relativeTime | dayjs().subtract(7, 'day').fromNow()→ |
First day of this month | dayjs().startOf('month').format('YYYY-MM-DD')→ |
Last day of this year | dayjs().endOf('year').format('YYYY-MM-DD')→ |
Start of this week (locale aware) | dayjs().startOf('week').format('YYYY-MM-DD ddd')→ |
Days between two dates | dayjs().diff(dayjs('2022-01-01'), 'day')→ |
Days in this month | dayjs().daysInMonth()→ |
Quarter of the year Day.js: quarterOfYear | dayjs().quarter()→ |
Calendar time Day.js: calendar | dayjs().add(1, 'day').calendar()→ |
Is a date between two others Day.js: isBetween | dayjs('2024-12-31').isBetween('2024-01-01', '2025-01-01')→ |
Is it today Day.js: isToday | dayjs().isToday()→ |
Is it a leap year Day.js: isLeapYear | dayjs('2024-01-01').isLeapYear()→ |
Validate a date strictly Day.js: customParseFormat | dayjs('2023-02-30', 'YYYY-MM-DD', true).isValid()→ |
Parse a custom format Day.js: customParseFormat | dayjs('13/10/2026 14:30', 'DD/MM/YYYY HH:mm').format()→ |
Unix timestamp in seconds | dayjs().unix()→ |
Current time in UTC Day.js: utc | dayjs.utc().format()→ |
Time in another time zone Day.js: utc + timezone + advancedFormat | dayjs().tz('America/New_York').format('YYYY-MM-DD HH:mm z')→ |
Humanize a duration Day.js: duration + relativeTime | dayjs.duration(90, 'minutes').humanize()→ |
Add a month at the end of a month | dayjs('2026-01-31').add(1, 'month').format('YYYY-MM-DD')→ |
Call add() without reassigning | (() => { const d = dayjs('2026-01-01'); d.add(1, 'day'); return d.format('YYYY-MM-DD') })()→ |
Code runner
Type an expression that uses dayjs. It runs right here in your browser, with every plugin from the recipes enabled and the locale above.
Day.js Oyun Alanı ve Biçim Başvurusu nasıl kullanılır
Seçtiğiniz bir tarihe karşı Day.js biçimlendirme, ayrıştırma, göreli zaman ve sürelerini deneyin; çıktı yazdıkça güncellenir. Her sonuç, ihtiyaç duyduğu import ve dayjs.extend() satırlarıyla gelir ve bir belirteç tablosu her biçim belirtecinin hangi eklentiyi gerektirdiğini gösterir.
- 1
Başvuru tarihi ve saatini ayarlayın (veya Şimdi'ye tıklayın), bir Yerel ayar seçin ve kodunuz dayjs.utc() kullanıyorsa UTC olarak ele al'ı açın.
- 2
Biçim dizisi'ne bir örüntü yazın veya bir hazır ayara tıklayın; imlece eklemek için Biçim belirteçleri'ndeki herhangi bir belirtece tıklayın.
- 3
Çıktı altındaki üretilen kodu kopyalayın; ihtiyaç duyduğu eklenti içe aktarmalarını zaten içerir.
- 4
Ayrıştırma oyun alanında bir Tarih dizisi ve Beklenen biçim girin ve var olmayan tarihleri reddetmek için Katı ayrıştırma'yı açın.
- 5
Tarifler'den herhangi birinde Dene'ye tıklayarak Kod çalıştırıcı'ya yükleyin, ardından düzenleyin ve sonucun güncellenmesini izleyin.
Sık sorulan sorular
Bir biçim belirteci için hangi eklentiye ihtiyacım var?
Biçim belirteçleri'nin Day.js sütunu core der veya eklentiyi adlandırır; örneğin Do, Q ve X için advancedFormat ya da L ve LLLL için localizedFormat. Kod parçacığı eşleşen import ve dayjs.extend() satırlarını sizin için ekler.
Bir belirteç burada çalışıp projemde neden yanlış çıkıyor?
Bu oyun alanı her eklentiyi yükler. Day.js çekirdeği yalnızca bildiği belirteçleri değiştirir; advancedFormat olmadan Q, Q olarak kalır ve Do, gün numarasının ardından başıboş bir o olur. Tablonun adlandırdığı eklentiyi genişletin; DDD veya E gibi birkaç Moment belirteci Day.js'te hiç yoktur.
2023-02-30 neden geçerli bir tarih olarak kabul ediliyor?
Katı kip olmadan Day.js olanaksız bir günü bir sonraki aya devirir. Katı ayrıştırma'yı açın (üçüncü argüman, true, customParseFormat eklentisiyle) ve aynı girdi geçersiz olarak bildirilir.
Bir biçime düz metni nasıl koyarım?
Köşeli parantez içine alın. Örneğin [Week] W, GGGG, Week sözcüğünü ve ardından ISO hafta numarası ile yılı basar.
Kod çalıştırıcı kodumu bir yere gönderiyor mu?
Hayır. Day.js, eklentileri ve yerel ayar dosyaları bu sayfanın içinde çalışır ve ifadeniz, tariflerin kullandığı her eklenti açıkken tarayıcınızda değerlendirilir.
Bir saati başka bir saat dilimine dönüştürebilir miyim?
Başka bir saat dilimindeki saat tarifi, utc ve timezone eklentileriyle dayjs().tz() gösterir. Birkaç dilimi yan yana karşılaştırmak için Saat Dilimi Dönüştürücü'yü kullanın.