Day.js प्लेग्राउंड और प्रारूप संदर्भ
- फ़ाइलें आपके डिवाइस से बाहर नहीं जातीं
- ब्राउज़र में चलता है
- मुफ़्त, बिना खाते, बिना वॉटरमार्क
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 प्लेग्राउंड और प्रारूप संदर्भ का उपयोग कैसे करें
आपकी चुनी तिथि पर Day.js फ़ॉर्मैटिंग, पार्सिंग, सापेक्ष समय और अवधि आज़माएँ, आउटपुट टाइप करते ही अपडेट होता है। हर परिणाम के साथ उसके लिए ज़रूरी import और dayjs.extend() पंक्तियाँ आती हैं, और टोकन तालिका दिखाती है कि हर प्रारूप टोकन को कौन सा प्लगइन चाहिए।
- 1
संदर्भ तिथि और समय सेट करें (या अभी पर क्लिक करें), लोकल चुनें, और यदि आपका कोड dayjs.utc() उपयोग करता है तो UTC मानें चालू करें।
- 2
प्रारूप स्ट्रिंग में पैटर्न टाइप करें या प्रीसेट पर क्लिक करें; कर्सर पर डालने के लिए प्रारूप टोकन में किसी टोकन पर क्लिक करें।
- 3
आउटपुट के अंतर्गत बना कोड कॉपी करें, जिसमें ज़रूरी प्लगइन import पहले से शामिल हैं।
- 4
पार्स प्लेग्राउंड में तिथि स्ट्रिंग और अपेक्षित प्रारूप दर्ज करें, और जो तिथियाँ मौजूद नहीं उन्हें अस्वीकार करने के लिए सख्त पार्सिंग चालू करें।
- 5
किसी भी रेसिपी पर आज़माएँ क्लिक करके उसे कोड रनर में लोड करें, फिर संपादित करें और परिणाम अपडेट होते देखें।
अक्सर पूछे जाने वाले प्रश्न
प्रारूप टोकन के लिए मुझे कौन सा प्लगइन चाहिए?
प्रारूप टोकन का Day.js स्तंभ core कहता है या प्लगइन का नाम बताता है, उदाहरण के लिए Do, Q और X के लिए advancedFormat, या L और LLLL के लिए localizedFormat। कोड स्निपेट आपके लिए मेल खाता import और dayjs.extend() पंक्तियाँ जोड़ता है।
कोई टोकन यहाँ चलता है लेकिन मेरे प्रोजेक्ट में गलत क्यों निकलता है?
यह प्लेग्राउंड हर प्लगइन लोड करता है। Day.js core केवल जाने टोकन बदलता है, इसलिए advancedFormat के बिना Q, Q ही रहता है और Do दिन संख्या के बाद भटका o बन जाता है। तालिका जिस प्लगइन का नाम ले वह विस्तारित करें; कुछ Moment टोकन, जैसे DDD या E, Day.js में बिल्कुल मौजूद नहीं हैं।
2023-02-30 मान्य तिथि क्यों मानी जाती है?
सख्त मोड के बिना Day.js असंभव दिन को अगले महीने में घुमा देता है। सख्त पार्सिंग चालू करें (तीसरा तर्क, true, customParseFormat प्लगइन के साथ) और वही इनपुट अमान्य बताया जाता है।
प्रारूप में सादा पाठ कैसे डालूँ?
उसे वर्गाकार कोष्ठक में लपेटें। उदाहरण के लिए, [Week] W, GGGG शब्द Week के बाद ISO सप्ताह संख्या और वर्ष छापता है।
क्या कोड रनर मेरा कोड कहीं भेजता है?
नहीं। Day.js, उसके प्लगइन और लोकल फ़ाइलें इसी पृष्ठ के भीतर चलती हैं, और आपका व्यंजक आपके ब्राउज़र में उन सभी प्लगइन के साथ मूल्यांकित होता है जिनका रेसिपी उपयोग करती हैं।
क्या मैं समय को दूसरे समय क्षेत्र में बदल सकता हूँ?
दूसरे समय क्षेत्र में समय रेसिपी utc और timezone प्लगइन के साथ dayjs().tz() दिखाती है। कई क्षेत्रों की साथ-साथ तुलना के लिए समय क्षेत्र कनवर्टर उपयोग करें।