parseTime
SourceParse a string into its constituent time parts
Returns an object containing the hour
, minute
, second
, millisecond
and optional timezone
values.
Accepts input of the form H:MM[:SS[:.mmm:[+TZ]]]
where H
is hours, MM
is minutes, SS
is seconds, mmm
is
milliseconds and +TZ
is the timezone (eg. +10:00).
Seconds & milliseconds are optional and will default to 0 if not in the string, timezone is optional and will be left as undefined if not specified.
NOTE: If you pass a Date
object then the timezone offset will always be whatever the local browser/env timezone
is (ie. it's not possible to have a javascript Date
object in another timezone).
parseTime("3:55")// { hour: 3, minute: 55, seconds: 0, milliseconds: 0 }parseTime("03:55:20")// { hour: 3, minute: 55, seconds: 20, milliseconds: 0 }parseTime("03:55:20.600")// { hour: 3, minute: 55, seconds: 20, milliseconds: 600 }parseTime("03:55:20.600+10:00")// { hour: 3, minute: 55, seconds: 20, milliseconds: 600, timezoneOffset: -600 }
Parameter | Type | Description | |
---|---|---|---|
* | value | string|Date | The string value to parse |
Key | Type | Description |
---|---|---|
hour | number | |
millisecond | number | |
minute | number | |
second | number | |
timezoneOffset | number | The difference in minutes between a date as evaluated in the UTC time zone and the same date in the local time zone. |