Please disable your adblock and script blockers to view this page

Moment.js Project Status


the Intl object
Luxon
Chrome Dev Tools
Moment
Safari
API
Moment's API
JavaScript Date
page.js-Joda
Joda-Time
Noda Time
UTC
ISO 8601
MDN

The ECMA TC39 Temporal Proposal
Firefox
Linux
noGlobal
AMD
NPMImport
GitHub
the Parsing Guide
moment#format
LT LTS L
SS
SSS
SSSS
SSSSSSSSS
Hmmss
Microsoft
JSON
ASP.NET
moment#utcOffset
moment#parsingFlags
NaN
jQuery
ISO weeks
a.max(b
min
DST
string.moment#utcOffset
ISO8601
Universal Time
2.13.0.Because
LDML
YYYY-MM
Atlantic/Reykjavik
moment#toNow
moment#diff
unit.moment#valueOf
Date().When
moment().isBefore
true.moment#isLeapYear
AA-BB
AA-CC
HTTP
JSPM
UMD
2.11.0
M.Note
Locale#week.doy
BC
Infinity
moment.duration().milliseconds().It
Duration#x
ISO8601
OLE Automation
Convert
OA
Twix
Python
Shamsi
Hijri
etc.).It
JavaScripts
@researchgate
Wikipedia
DaniSchenk
MIT


Day.js
Isaac Cambron
Require.js
2.18.1
Install
Typescript
compilerOptions
Java/Rhino
Gitter
Moment.js

mm
Z ZZ
HTML5_FMT
day-of-the-month.date
NaN
moment#week
a.min(b
LDML
Ben Oakes'
moment#format
ssZ.As
2.13.0
ss[Z
2.10.3
ES2015
console.warn
moment#locale
moment#calendar
Locale#isPM
23:59:59.999.As
moment.duration().asSeconds
moment.duration().months
Gianni Chiappetta's
Isaac Cambron's
Rob Dawson
day_of_week
Jalaali
Jalali
Khorshidi
Behrang Noruzi
Umm al-Qura
Suhail Alkowaileet
Casey Trimm's
JanuaryThis
Plugin
Demo | SourceThis


Modern
Luxon
belowIn
Dec 31.Gets
english
Arabic
Dutch
Pseudo
Duration#as('x
Markit
Persian
German
16 German


Node.js
JavaScript
isFuture
moment.relativeTimeThreshold(unit
moment.duration().asMilliseconds


Three-Ten Backport
String).As
Universal Time
moment#fromNow.moment#calendar


@jrburke
Demandware
moment#format
US
UTC
Moment.js
moment(string
moment().year(year).month(month).date(day)2.16.0
the United States
France
month.2.16.0
2.8.4.SSSS
referenceDay
(United States
isFormat
L LL
2.8.1.Note
janX
BC
moment#subtract
moment.duration().seconds().It
moment.duration().hours
github.com/rotaready/moment-range.Another
@hijonathan
Taiwan
taiwan

No matching tags

Positivity     42.00%   
   Negativity   58.00%
The New York Times
SOURCE: https://momentjs.com/docs/#/-project-status/
Write a review: Hacker News
Summary

Unlike a Moment object, it can not be set to use another time zone; It has no concept of "mode".Using Date.parse, or new Date(<string>) Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers.For consistent results parsing anything other than ISO 8601 strings, you should use String + Format.An ISO 8601 string requires a date part.A time part can also be included, separated from the date part by a space or an uppercase T.Any of the date parts can have a time part.If a time part is included, an offset from UTC can also be included as +-HH:mm, +-HHmm, +-HH or Z.Note: Support for the week and ordinal formats was added in version 2.3.0.If a string does not match any of the above formats and is not able to be parsed with Date.parse, moment#isValid will return false.Before parsing a RFC 2822 date time the string is cleansed to remove any comments and/or newline characters. The additional characters are legal in the format but add nothing to creating a valid moment instance.After cleansing, the string is validated in the following space-separated sections, all using the English language:[*] See section 4.3 of the specification for details.The parser also confirms that the day-of-week (when included) is consistent with the date.If you know the format of an input string, you can use that to parse a moment.The parser ignores non-alphanumeric characters by default, so both of the following will return the same thing.You may get unexpected results when parsing both date and time. The below example may not parse as you expect:You can use strict mode, which will identify the parsing error and set the Moment object as invalid:The parsing tokens are similar to the formatting tokens used in moment#format.Tokens are case-sensitive.YYYY from version 2.10.5 supports 2 digit years, and converts them to a year The only argument of this method is a string containing the two years input by the user, and should return the year as an integer.From version 2.11.0 parsing hmm, Hmm, hmmss and Hmmss is supported:If you don't know the exact format of an input string, but know it could be one of many, you can use an array of formats.This is the same as String + Format, only it will try to match the input to multiple formats.Starting in version 2.3.0, Moment uses some simple heuristics to determine which format to use. Moment already supports parsing iso-8601 strings, but this can be specified explicitly in the format/list of formats when constructing a moment.To specify iso-8601 parsing use moment.ISO_8601 constant.As of version 2.20.0, the following HTML5 formats are available as constants in the moment object's HTML5_FMT property (moment.HTML5_FMT.*):You can create a moment by specifying some of the units in an object.Omitted units default to 0 or the current date, month, and year.day and date key both mean day-of-the-month.date was added in 2.8.4.String values (as shown on the last line) are supported from version 2.11.0.Note that like moment(Array) and new Date(year, month, date), months are 0 indexed.Similar to new Date(Number), you can create a moment by passing an integer value representing the number of milliseconds since the Unix Epoch (Jan 1 1970 12AM UTC). Note: ECMAScript calls this a "Time Value" To create a moment from a Unix timestamp (seconds since the Unix Epoch), use moment.unix(Number).This is implemented as moment(timestamp * 1000), so partial seconds in the input timestamp are included.Note: Despite Unix timestamps being UTC-based, this function creates a moment object in local mode. If you need UTC, then subsequently call .utc(), as in:You can create a Moment with a pre-existing native Javascript Date object.This clones the Date object; further changes to the Date won't affect the Moment, and vice-versa.You can create a moment with an array of numbers that mirror the parameters passed to new Date()[year, month, day, hour, minute, second, millisecond]Any value past the year is optional, and will default to the lowest possible number.Construction with an array will create a date in the current time zone. To create a date from an array at UTC, use moment.utc(Number[]).Note: Because this mirrors the native Date parameters, months, hours, minutes, seconds, and milliseconds are all zero indexed. Years and days of the month are 1 indexed.This is often the cause of frustration, especially with months, so take note!If the date represented by the array does not exist, moment#isValid will return false.Microsoft Web API returns JSON dates in proper ISO-8601 format by default, but older ASP.NET technologies may return dates in JSON as /Date(1198908717056)/ or /Date(1198908717056-0700)/If a string that matches this format is passed in, it will be parsed correctly.All moments are mutable. UTC mode.While in UTC mode, all display methods will display in UTC time instead of local time.Additionally, while in UTC mode, all getters and setters will internally use the Date#getUTC* and Date#setUTC* methods instead of the Date#get* and Date#set* methods.It is important to note that though the displays differ above, they are both the same moment in time.Any moment created with moment.utc() will be in UTC mode, and any moment created with moment() will not.To switch from UTC to local time, you can use moment#utc or moment#local.Moment's string parsing functions like moment(string) and moment.utc(string) accept offset information if provided, but convert the resulting Moment object to local or UTC time. seconds and milliseconds.Defaulting to now, when nothing is passed:Defaulting to today, when only hours, minutes, seconds and milliseconds are passed:Defaulting to this month and year, when only days and smaller units are passed:Defaulting to this year, if year is not specified:Moment.js uses overloaded getters and setters. Use moment().date() instead.Gets or sets the day of the week.This method can be used to set the day of the week, with Sunday as 0 and Saturday as 6.If the value given is from 0 to 6, the resulting date will be within the current (Sunday-to-Saturday) week.If the range is exceeded, it will bubble up to other weeks.Note: Moment#date is for the date of the month, and Moment#day is for the day of the week.As of 2.1.0, a day name is also supported. second (seconds, s), millisecond (milliseconds, ms).Object parsing was added in 2.9.0Returns the maximum (most distant future) of the given moment instances.For example:With no arguments the function returns a moment instance with the current time.From version 2.10.5, if an invalid moment is one of the arguments, the result If you are adding years, months, weeks, or days, the original hour will always match the added hour.Adding a month will add the specified number of months to the date.If you are adding hours, minutes, seconds, or milliseconds, the assumption is that you want precision to the hour, and will result in a different hour.Alternatively, you can use durations to add to moments.Before version 2.8.0, the moment#add(String, Number) syntax was also supported. Weeks, quarters, and years are converted to days or months, and then rounded to the nearest integer.Mutates the original moment by subtracting time.This is exactly the same as moment#add, only instead of adding time, it subtracts time.Before version 2.8.0, the moment#subtract(String, Number) syntax was also supported. Weeks, quarters, and years are converted to days or months, and then rounded to the nearest integer.Note that in order to make the operations moment.add(-.5, 'days') and moment.subtract(.5, 'days') equivalent, -.5, -1.5, -2.5, etc are rounded down.Mutates the original moment by setting it to the start of a unit of time.These shortcuts are essentially the same as the following.As of version 2.0.0, moment#startOf('day') replaced moment#sod.Note: moment#startOf('week') was added in version 2.0.0.As of version 2.1.0, moment#startOf('week') uses the locale aware week start day.Note: moment#startOf('isoWeek') was added in version 2.2.0.Note: moment#startOf('date') was added as an alias for day in 2.13.0Mutates the original moment by setting it to the end of a unit of time.This is the same as moment#startOf, only instead of setting to the start of a unit of time, it sets to the end of a unit of time.As of version 2.0.0, moment#endOf('day') replaced moment#eod.Note: moment#endOf('week') was added in version 2.0.0.As of version 2.1.0, moment#endOf('week') uses the locale aware week start day.Note: This function has been deprecated in 2.7.0. So a.min(b) is the same as a = moment.max(a, b) (note that min is converted to max).This is the counterpart for moment#max.This can be used in conjunction with moment#max to clamp a moment to a range.Sets a flag on the original moment to use local time to display a moment instead of the original moment's time.Local can also be used to convert out of a fixed offset mode:Passing true will change the time zone without changing the current time.See moment.utc() for more information on UTC mode.Sets a flag on the original moment to use UTC to display a moment instead of the original moment's time.UTC can also be used to convert out of a fixed offset mode:Passing true will change the time zone without changing the current time.See moment.utc() for more information on UTC mode.Get or set the UTC offset in minutes.Note: Unlike moment.fn.zone this Consider moment.fn.utcOffset instead.Get the time zone offset in minutes.As of version 2.1.0, it is possible to set the offset by passing in the number of minutes offset from GMT.If the input is less than 16 and greater than -16, it will interpret your input as hours instead.It is also possible to set the zone from a string.moment#zone will search the string for the first match of +00:00 +0000 -00:00 -0000, so you can even pass an ISO8601 formatted string and the moment will be changed to that zone.Once parsing and manipulation are done, you need some way to display the moment.This is the most robust display option. LTS was added in 2.8.4.To escape characters in format strings, you can wrap the characters in square brackets.Note: While these date formats are very similar to LDML date formats, there are a few minor differences regarding day of month, day of year, and day of week.For a breakdown of a few different date formatting tokens across different locales, see this chart of date formatting tokens.To compare Moment.js formatting speed against other libraries, check out this comparison against other libraries.If you are more comfortable working with strftime instead of LDML-like parsing tokens, you can use Ben Oakes' plugin. Time is rounded to the nearest second.The breakdown of which string is displayed for each length of time is outlined in the table below.Note: From version 2.10.3, if the target moment object is invalid the result is the localized Invalid date string.Note: The ss key was added in 2.18.0. points of the interval.If you pass true, you can get the value without the prefix.The base strings are customized by the current locale.The breakdown of which string is displayed for each length of time is outlined in the table below.From version 2.10.3, if the target moment object is invalid the result is localized Invalid date string.Calendar time displays time relative to a given referenceDay (defaults to the start of today), but does so slightly differently than moment#fromNow.moment#calendar will format a date with different strings depending on how close to referenceDay's date (today by default) the date is.These strings are localized, and can be customized.From 2.10.5 moment supports specifying calendar output formats per Note: ECMAScript calls this a "Time Value" moment#unix outputs a Unix timestamp (the number of seconds since the Unix Epoch).This value is floored to the nearest second, and does not include a milliseconds component.Get the number of days in the current month.To get a copy of the native Date object that Moment.js wraps, use moment#toDate.This will return a copy of the Date that the moment uses, so any changes to that Date will not cause moment to change. If you want to change the moment Date, see moment#manipulate or moment#set.moment#native has been replaced by moment#toDate and has been deprecated as of 1.6.0.This returns an array that mirrors the parameters from new Date().When serializing an object to JSON, if there is a Moment object, it will be represented as an ISO8601 string, adjusted to UTC.If instead you would like an ISO8601 string that reflects the moment's utcOffset(), then you can modify the toJSON function like this:This changes the behavior as follows:Formats a string to the ISO8601 standard.Note that .toISOString() returns a timestamp in UTC, even if the moment in question is in local mode. The first argument will be parsed as a moment, if not already so.If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.Like moment#isAfter and moment#isSame, any of the units of time that are supported for moment#startOf are supported for moment#isBefore.If nothing is passed to moment#isBefore, it will default to the current time.NOTE: moment().isBefore() has undefined behavior and should not be used! The first argument will be parsed as a moment, if not already so.If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.Like moment#isSame and moment#isBefore, any of the units of time that are supported for moment#startOf are supported for moment#isAfter.If nothing is passed to moment#isAfter, it will default to the current time.Check if a moment is before or the same as another moment. The first argument will be parsed as a moment, if not already so.If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.Like moment#isAfter and moment#isSame, any of the units of time that are supported for moment#startOf are supported for moment#isSameOrBefore:Check if a moment is after or the same as another moment. The first argument will be parsed as a moment, if not already so.If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.Like moment#isSame and moment#isBefore, any of the units of time that are supported for moment#startOf are supported for moment#isSameOrAfter:Check if a moment is between two other moments, optionally looking at unit increment toward +Infinity since < until.Parsing/formatting of eras is accomplished with yo, y* and N* tokens.Note: The era-related APIs are subject to change.Locale#invalidDate should be a string.Moment.js also has duration objects. It is much better to use moment#diff for calculating days or years between two moments than to use Durations.As discussed here, the duration format for Moment.js differs very slightly from the specifications for ISO 8601 nominal duration and RFC 5545 duration.To create a duration, call moment.duration() with the length of time in milliseconds.If you want to create a moment with a unit of measurement other than milliseconds, you can pass the unit of measurement as well.The same shorthand for moment#add and moment#subtract works here as well.Much like moment#add, you can pass an object of values if you need multiple different units of measurement.As of 2.1.0, moment supports parsing ASP.NET style time spans. argument or after suffix arg:Note: Passing thresholds in humanize was added in 2.25.0.To get the number of milliseconds in a duration, use moment.duration().milliseconds().It will return a number between 0 and 999.If you want the length of the duration in milliseconds, use moment.duration().asMilliseconds() instead.To get the number of seconds in a duration, use moment.duration().seconds().It will return a number between 0 and 59.If you want the length of the duration in seconds, use moment.duration().asSeconds() instead.As with the other getters for durations, moment.duration().minutes() gets the minutes (0 - 59).moment.duration().asMinutes() gets the length of the duration in minutes.As with the other getters for durations, moment.duration().hours() gets the hours (0 - 23).moment.duration().asHours() gets the length of the duration in hours.As with the other getters for durations, moment.duration().days() gets the days (0 - 30).moment.duration().asDays() gets the length of the duration in days.As with the other getters for durations, moment.duration().weeks() gets the weeks (0 - 4).moment.duration().asWeeks() gets the length of the duration in weeks.Pay attention that unlike the other getters for duration, weeks are counted as a subset of the days, and are not taken off the days count.Note: The length of a duration in weeks is defined as 7 days.As with the other getters for durations, moment.duration().months() gets the months (0 - 11).moment.duration().asMonths() gets the length of the duration in months.As with the other getters for durations, moment.duration().years() gets the years.moment.duration().asYears() gets the length of the duration in years.Mutates the original duration by adding time.The same keys and shorthands used to create durations can be used here as the second argument.Note that adding an invalid duration to any other duration results in an invalid ISO8601 string.Invalid durations return Invalid Date as json representation.To check if a variable is a moment duration object, use moment.isDuration().Returns duration in string as specified by ISO 8601 standard.Format PnYnMnDTnHnMnS description:You can get or set the locale of a duration using locale(...). For example,Full documentation of all the options and features is here.It's available on npm like so:Or just grab the JS file from here.The Precise Range plugin, written by Rob Dawson, can be used to display exact, human-readable representations of date/time ranges:To obtain the raw numeric values rather than a string, pass the value true as the third argument to the method:If you are looking for a Python-like isocalendar method, you can use Rocky Meza's pluginmoment-isocalendarCalling the isocalendar method on a moment will return an array like the following:[year, week_of_year, day_of_week, minutes_since_midnight]You can also reconstruct a moment from a isocalendar array.The repository is located at github.com/fusionbox/moment-isocalendar.If you want to work with Jalaali calendar system (Jalali, Persian, Khorshidi or Shamsi), you can use Behrang Noruzi Niya's plugin moment-jalaali.When installed, it will wrap moment and moment will be able to format and parse Jalaali years and months. Here is a short example:The repository is located at github.com/xsoh/moment-hijri.This is another Hijri calendar (based on civil calculations).The repository is located at github.com/ACGC/moment-islamic-civil.If you need to work with recurring dates, you can use Casey Trimm's plugin moment-recur.This plugin will allow you to create length-based intervals (days, weeks, etc.) and calendar-based intervals (daysOfMonth, monthsOfYear, etc.).It provides a matches function to test whether a date recurs according to the rules set, as well as generator functions to get the next and previous dates in a series.The repository, documentation, and many more examples can be found at github.com/c-trimm/moment-recurIf you're trying to format times for tweets like the way Twitter does, you can use the moment.twitter plugin by @hijonathan.It's a simple way to display both short and long versions of human-readable timestamps.Yes, it does smart pluralization.Not short enough for you?If you ever have need for Fiscal, Calendar or Academic quarters, you can use the moment-fquarter plugin by @robgallen.At its simplest, just call the fquarter method on any moment object. You can use basic operations –set/add/subtract– on individual parts (hours, month, …) of a Moment instance.Optional parameters lets you specify custom patterns and force strict pattern usage (non-alphabetic characters are not mandatory in passed string by default).You can see it live there while the repository is here.If you want to work with Taiwan calendar system , you can use Bradwoo8621's plugin moment-taiwan.When installed, it will wrap moment and moment will be able to format and parse Taiwan years. are non-work days.For example,The repository is located at github.com/jmeas/moment-business.If you want to format times in a short way, you can use the moment-shortformat plugin by @researchgate.It is based on and similar to the moment.twitter plugin but has a different output.You can also disable the use of the relative time templatesIf the date is too far in the future or the past it will display like thatThis (moment-feiertage) is a Moment.js plugin to determine if a date is a German holiday.

As said here by