Skip to content
Day.js

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Appearance

Sidebar Navigation

Installation

Node.js

Browser

TypeScript

Download

Parse

Now

String

String + Format

Unix Timestamp (milliseconds)

Unix Timestamp (seconds)

Date

Object

Array

UTC

Dayjs Clone

Validation

Get + Set

Millisecond

Second

Minute

Hour

Date of Month

Day of Week

Day of Week (Locale Aware)

ISO Day of Week

Day of Year

Week of Year

Week of Year (ISO)

Month

Quarter

Year

Week Year

Week Year (ISO)

Weeks In Year (ISO)

Get

Set

Maximum

Minimum

Manipulate

Add

Subtract

Start of Time

End of Time

Local

UTC

UTC offset

Display

Format

Time from now

Time from X

Time to now

Time to X

Calendar Time

Difference

Unix Timestamp (milliseconds)

Unix Timestamp

Days in Month

As Javascript Date

As Array

As JSON

As ISO 8601 String

As Object

As String

Query

Is Before

Is Same

Is After

Is Same or Before

Is Same or After

Is Between

Is a Dayjs

Is Leap Year

i18n

Loading locale in NodeJS

Loading locale in the browser

Changing locale globally

Changing locales locally

Checking the current Day.js locale

Listing the months and weekdays of the current locale

Accessing locale specific functionality

Plugins

Loading plugin in NodeJS

Loading plugin in the browser

AdvancedFormat

ArraySupport

BadMutable

BigIntSupport

BuddhistEra

Calendar

CustomParseFormat

DayOfYear

DevHelper

Duration

IsBetween

IsLeapYear

IsSameOrAfter

IsSameOrBefore

IsToday

IsTomorrow

IsYesterday

IsoWeek

IsoWeeksInYear

LocaleData

LocalizedFormat

MinMax

ObjectSupport

PluralGetSet

PreParsePostFormat

QuarterOfYear

RelativeTime

Timezone

ToArray

ToObject

UpdateLocale

UTC

weekOfYear

WeekYear

Weekday

Customize

Month Names

Month Abbreviations

Weekday Names

Weekday Abbreviations

Minimal Weekday Abbreviations

Relative Time

Calendar

Durations

Creating

Clone

Humanize

Format

Milliseconds

Seconds

Minutes

Hours

Days

Weeks

Months

Years

Add Time

Subtract Time

Using Duration with Diff

As Unit of Time

Get Unit of Time

As JSON

Is a Duration

As ISO 8601 String

Locale

Time Zone

Parsing in Zone

Converting to Zone

Guessing user zone

Set Default Timezone

On this page

String + Format ​

If you know the format of an input string, you can use that to parse a date.

TIP

This requires the CustomParseFormat plugin to work

js
dayjs.extend(customParseFormat);
dayjs('12-25-1995', 'MM-DD-YYYY');

Pass the locale key as the third parameter to parse locale-aware date time string.

js
require('dayjs/locale/es');
dayjs('2018 Enero 15', 'YYYY MMMM DD', 'es');

You may specify a boolean for the last argument to use strict parsing. Strict parsing requires that the format and input match exactly, including delimiters.

js
dayjs('1970-00-00', 'YYYY-MM-DD').isValid(); // true
dayjs('1970-00-00', 'YYYY-MM-DD', true).isValid(); // false
dayjs('1970-00-00', 'YYYY-MM-DD', 'es', true).isValid(); // false

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.

js
dayjs('12-25-2001', ['YYYY', 'YYYY-MM-DD'], 'es', true);

List of all available parsing tokens ​

InputExampleDescription
YY01Two-digit year
YYYY2001Four-digit year
M1-12Month, beginning at 1
MM01-12Month, 2-digits
MMMJan-DecThe abbreviated month name
MMMMJanuary-DecemberThe full month name
D1-31Day of month
DD01-31Day of month, 2-digits
H0-23Hours
HH00-23Hours, 2-digits
h1-12Hours, 12-hour clock
hh01-12Hours, 12-hour clock, 2-digits
m0-59Minutes
mm00-59Minutes, 2-digits
s0-59Seconds
ss00-59Seconds, 2-digits
S0-9Hundreds of milliseconds, 1-digit
SS00-99Tens of milliseconds, 2-digits
SSS000-999Milliseconds, 3-digits
Z-05:00Offset from UTC
ZZ-0500Compact offset from UTC, 2-digits
AAM PMPost or ante meridiem, upper-case
aam pmPost or ante meridiem, lower-case
Do1st... 31stDay of Month with ordinal
X1410715640.579Unix timestamp
x1410715640579Unix ms timestamp

Differences to moment ​

titleparametersdayjsmoment
invalid date with overflow('35/22/2010 99:88:77', 'DD-MM-YYYY HH:mm:ss')'08-11-2011 04:29:17''Invalid date'
invalid date with overflow, strict('35/22/2010 99:88:77', 'DD-MM-YYYY HH:mm:ss', true)'Invalid Date''Invalid date'
'0' day or month (using default values)('1970-00-00', 'YYYY-MM-DD')'1970-01-01''Invalid date'
'0' day or month (using default values), strict('1970-00-00', 'YYYY-MM-DD', true)'Invalid Date''Invalid date'
date not matching format('10/12/2014', 'YYYY-MM-DD')'01-01-2014''12-20-2010'
date not matching format, strict('10/12/2014', 'YYYY-MM-DD', true)'Invalid Date''Invalid date'
first match vs. longest match('2012-05-28 10:21:15', ['YYYY', 'YYYY-MM-DD', 'YYYY-MM-DD HH:mm:ss'])'2012-01-01 00:00:00''2012-05-28 10:21:15'
first match vs. longest match, strict('2012-05-28 10:21:15', ['YYYY', 'YYYY-MM-DD', 'YYYY-MM-DD HH:mm:ss'], true)'2012-05-28 10:21:15''2012-05-28 10:21:15'

List of all recognized separator characters: ​

-_:.,()/

Pager
Previous pageString
Next pageUnix Timestamp (milliseconds)

Released under the MIT License.

Copyright (c) 2020 iamkun

https://day.js.org/docs/en/parse/string-format

Released under the MIT License.

Copyright (c) 2020 iamkun