ChronosChronos

parse

Parse an unknown format date string into a Chronos instance.

parse()

Parses a date string according to the specified format and returns a new Chronos instance.

Signature

static parse(dateStr: string, format: string): Chronos

Parameters

  • dateStr: The date string to parse
  • format: The format pattern defining how to interpret the date string

Return Type

  • Chronos - A new instance representing the parsed date

Supported Format Tokens

TokenDescriptionRangeExample
Four-digit year0000-99992025
Two-digit year (20th/21st century)00-9925 → 2025, 99 → 1999
Two-digit month01-1202
One or two-digit month1-122
Two-digit day of month01-3105
One or two-digit day of month1-315
Two-digit hour (24-hour)00-2309
One or two-digit hour (24-hour)0-239
Two-digit minute00-5905
One or two-digit minute0-595
Two-digit second00-5909
One or two-digit second0-599
Three-digit millisecond000-999099
One to three-digit millisecond0-99999

Example

playground.ts

Throws

  • Error - When the input date string does not match the specified format pattern

Remarks

  • The parser uses regular expressions to match the format pattern against the input string
  • All unmatched components default to their minimum values (year: 1970, month: 1, day: 1, time: 00:00:00.000)
  • Two-digit years (YY) are interpreted as years in the 20th/21st century (00-99 → 2000-2099)
  • The method creates a new Chronos instance with the origin set to 'parse'

Last updated: Thu, May 21, 2026 07:12:18AM (UTC)

On this page