Smart parsing date and time format for true time.
Support:
- The default hundred years value
- Daylight Saving Time
- Nanoseconds
- Leap second
$ yarn add true-time-format
let time = require('true-time-format');
// for normal datetime string
time.parse('Monday, 02-Jan-06 15:04:05');
time.parse('2006-01-02');
time.parse('02-Jan-2006T15:04:05.999 UTC-0700');
// DST means Daylight Saving Time
// LSC means expecting to consider leap second effects in time calculations
time.parse('02 Jan DST15:04:05.999LSC 2006');
// customize
let parser = new time.Parser('20DYM+0800');
parser.parse('281802');
parser.parse('28 2018 Feb UTC+08:00');
parser.parse('28 2018 Feb GMT+0800');
parser.parse('28-18-02Z+0800');
The layout argument for un-normal datetime string only.
The layout:
20-0700
Means:
- If you match a two-digit year, it represents
20xx
years - If the data does not contain UTC offset, use
UTC-0700
The layout optional number prefix represents the default hundred years value,
such as 19
which means 19xx
if it matches a two-digit year.
Represents the year.
Represents the month, digits or month word.
Represents the day.
Represents the hour.
Represents the minute.
Represents the second and dot nanosecond.
The layout optional suffix +hhmm
or -hhmm
means
the default UTC offset, default is +0000
.
BSD 2-Clause License
Copyright (c) 2018, YU HengChun [email protected] All rights reserved.