Moment.js प्लेग्राउंड और Day.js माइग्रेशन

Moment.js प्रारूप लाइव आज़माएँ और Day.js समकक्ष साथ-साथ देखें
  • फ़ाइलें आपके डिवाइस से बाहर नहीं जातीं
  • ब्राउज़र में चलता है
  • मुफ़्त, बिना खाते, बिना वॉटरमार्क

Moment.js is in maintenance mode, and its own team recommends a modern library for new projects. Day.js keeps nearly the same API in about 2 KB, so every section here also shows the Day.js equivalent.

Moment project statusOpen the Day.js playground

Loading Moment.js…

Format playground

Output
 

Format tokens

Click a token to insert it into the format string. Examples use the reference date and locale.

TokenExampleMeaning
Year and quarter
Four-digit year
Two-digit year
Quarter (1–4)
Quarter, ordinal
Month
Month (1–12)
Month, ordinal
Month, two digits
Month, short name
Month, full name
Day of month and year
Day of month
Day of month, ordinal
Day of month, two digits
Day of year
Day of year, three digits
Day of week
Day of week (0 = Sunday)
Weekday, shortest name
Weekday, short name
Weekday, full name
Day of week, by locale
ISO day of week (1 = Monday)
Week
Week of year, by locale
Week of year, ordinal
Week of year, two digits
ISO week of year
ISO week, two digits
Week-numbering year, by locale
ISO week-numbering year
Hour
Hour, 0–23
Hour, 00–23
Hour, 1–12
Hour, 01–12
Hour, 1–24
Hour, 01–24
Minute and second
Minute
Minute, two digits
Second
Second, two digits
Tenths of a second
Hundredths of a second
Milliseconds
AM / PM
AM / PM
am / pm
Time zone
UTC offset, ±HH:mm
UTC offset, ±HHmm
needs moment-timezoneTime zone abbreviation
needs moment-timezoneTime zone name
Unix time
Unix seconds
Unix milliseconds
Localized formats
Localized time
Localized time with seconds
Localized numeric date
Localized date with month name
Localized date and time
Localized date and time with weekday
Short numeric date
Short date with month name
Short date and time
Short date and time with weekday
Escaping
Text in square brackets is printed as is

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().

Shiftfrom(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.

Moment objects are mutable: add() changes the original. Day.js returns a new object from every operation, so reassign the result.
TaskMoment.js
Format the current time
moment().format('YYYY-MM-DD HH:mm:ss')
→
Add days
moment('2023-01-01').add(1, 'days').format('YYYY-MM-DD')
→
Time from now
moment().subtract(7, 'days').fromNow()
→
First day of this month
moment().startOf('month').format('YYYY-MM-DD')
→
Last day of this year
moment().endOf('year').format('YYYY-MM-DD')
→
Start of this week (locale aware)
moment().startOf('week').format('YYYY-MM-DD ddd')
→
Days between two dates
moment().diff(moment('2022-01-01'), 'days')
→
Days in this month
moment().daysInMonth()
→
Quarter of the year
moment().quarter()
→
Calendar time
moment().add(1, 'days').calendar()
→
Is a date between two others
moment('2024-12-31').isBetween('2024-01-01', '2025-01-01')
→
Is it today
moment().isSame(moment(), 'day')
→
Is it a leap year
moment('2024-01-01').isLeapYear()
→
Validate a date strictly
moment('2023-02-30', 'YYYY-MM-DD', true).isValid()
→
Parse a custom format
moment('13/10/2026 14:30', 'DD/MM/YYYY HH:mm').format()
→
Unix timestamp in seconds
moment().unix()
→
Current time in UTC
moment.utc().format()
→
Time in another time zone
needs moment-timezone
Humanize a duration
moment.duration(90, 'minutes').humanize()
→
Add a month at the end of a month
moment('2026-01-31').add(1, 'months').format('YYYY-MM-DD')
→
Call add() without reassigning
(() => { const d = moment('2026-01-01'); d.add(1, 'days'); return d.format('YYYY-MM-DD') })()
→

Code runner

Type an expression that uses moment. It runs right here in your browser, with every plugin from the recipes enabled and the locale above.

Result

Moment.js प्लेग्राउंड और Day.js माइग्रेशन का उपयोग कैसे करें

Moment.js फ़ॉर्मैटिंग, पार्सिंग, सापेक्ष समय और अवधि जाँचें, हर Moment परिणाम के बगल में Day.js परिणाम के साथ। अंतर चिह्नित होते हैं, ताकि कोडबेस माइग्रेट करने से पहले आप देख सकें क्या बदलेगा। दोनों लाइब्रेरी आपके ब्राउज़र में चलती हैं।

  1. 1

    संदर्भ तिथि और समय तथा लोकल सेट करें, और यदि आपका कोड moment.utc() उपयोग करता है तो UTC मानें चालू करें।

  2. 2

    प्रारूप स्ट्रिंग में पैटर्न टाइप करें; आउटपुट Moment का परिणाम और Day.js क्या देता है दिखाता है, समान आउटपुट या अलग आउटपुट चिह्नित।

  3. 3

    प्रारूप टोकन तालिका में वे टोकन देखें जो Day.js में नहीं हैं या जिन्हें प्लगइन चाहिए, और डालने के लिए टोकन पर क्लिक करें।

  4. 4

    पार्स प्लेग्राउंड, सापेक्ष समय और अवधि में दोनों लाइब्रेरी की तुलना करें, जहाँ Day.js के अलग मान हाइलाइट होते हैं।

  5. 5

    रोज़मर्रा के कामों के साथ-साथ कोड के लिए रेसिपी उपयोग करें, और कोड रनर में Moment संस्करण चलाने के लिए आज़माएँ पर क्लिक करें।

अक्सर पूछे जाने वाले प्रश्न

क्या Moment.js अभी भी मेंटेन होता है?

Moment.js रखरखाव मोड में है, और उसकी अपनी टीम नए प्रोजेक्ट के लिए आधुनिक लाइब्रेरी की अनुशंसा करती है। ऊपर का नोट Moment प्रोजेक्ट स्थिति पृष्ठ और Day.js प्लेग्राउंड से लिंक करता है।

Day.js पर जाते समय आमतौर पर क्या टूटता है?

परिवर्तनीयता: Moment का add() मूल ऑब्जेक्ट बदलता है, जबकि Day.js नया लौटाता है, इसलिए परिणाम फिर से असाइन करने होते हैं। कई सुविधाओं को Day.js प्लगइन भी चाहिए, जिन्हें हर रेसिपी सूचीबद्ध करती है।

किन प्रारूप टोकन का Day.js में कोई समकक्ष नहीं है?

Qo, Mo, DDD, DDDD, e, E, S और SS। प्रारूप टोकन तालिका उन्हें Day.js में नहीं चिह्नित करती है और बाकी के लिए ज़रूरी प्लगइन का नाम बताती है।

Moment में z और zzz टोकन क्यों नहीं चलते?

समय क्षेत्र नामों को अलग moment-timezone ऐड-ऑन चाहिए, जिसे यह पृष्ठ लोड नहीं करता, इसलिए तालिका needs moment-timezone दिखाती है। Day.js उन्हें अपने timezone प्लगइन से देता है।

कौन से संस्करणों की तुलना होती है?

सटीक Moment.js और Day.js संस्करण सेटिंग पैनल के अंतर्गत दिखाए जाते हैं।

क्या मेरा कोड सर्वर पर भेजा जाता है?

नहीं। दोनों लाइब्रेरी और उनकी लोकल फ़ाइलें इसी पृष्ठ में लोड होती हैं, और आप जो टाइप करते हैं वह आपके ब्राउज़र में मूल्यांकित होता है।