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): ChronosParameters
dateStr: The date string to parseformat: The format pattern defining how to interpret the date string
Return Type
Chronos- A new instance representing the parsed date
Supported Format Tokens
| Token | Description | Range | Example |
|---|---|---|---|
| Four-digit year | 0000-9999 | 2025 | |
| Two-digit year (20th/21st century) | 00-99 | 25 → 2025, 99 → 1999 | |
| Two-digit month | 01-12 | 02 | |
| One or two-digit month | 1-12 | 2 | |
| Two-digit day of month | 01-31 | 05 | |
| One or two-digit day of month | 1-31 | 5 | |
| Two-digit hour (24-hour) | 00-23 | 09 | |
| One or two-digit hour (24-hour) | 0-23 | 9 | |
| Two-digit minute | 00-59 | 05 | |
| One or two-digit minute | 0-59 | 5 | |
| Two-digit second | 00-59 | 09 | |
| One or two-digit second | 0-59 | 9 | |
| Three-digit millisecond | 000-999 | 099 | |
| One to three-digit millisecond | 0-999 | 99 |
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
Chronosinstance with the origin set to'parse'
Last updated: Thu, May 21, 2026 07:12:18AM (UTC)
