minitz

minitz

new minitz(year, month, day, hour, minute, second, timezone, throwOnInvalidTimeopt) → {date}

Converts a date/time from a specific timezone to a normal date object using the system local time

Shortcut for minitz.fromTZ(minitz.tp(...));

Parameters:
year ( Number )

1970--

month ( Number )

1-12

day ( Number )

1-31

hour ( Number )

0-24

minute ( Number )

0-60

second ( Number )

0-60

timezone ( string )

Time zone in IANA database format 'Europe/Stockholm'

throwOnInvalidTime ( boolean ) <optional>

Default is to return the adjusted time if the call happens during a Daylight-Saving-Time switch. E.g. Value "01:01:01" is returned if input time is 00:01:01 while one hour got actually skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw an exception instead.

Source:

Methods

(static) .fromTZ(date, throwOnInvalidTimeopt) → {date}

Converts a date/time from a specific timezone to a normal date object using the system local time

Parameters:
date ( TimePoint )

Object with specified timezone

throwOnInvalidTime ( boolean ) <optional>

Default is to return the adjusted time if the call happens during a Daylight-Saving-Time switch. E.g. Value "01:01:01" is returned if input time is 00:01:01 while one hour got actually skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw an exception instead.

Source:

(static) .fromTZISO(localTimeString, timezone, throwOnInvalidTimeopt) → {date}

Converts a date/time from a specific timezone to a normal date object using the system local time

Parameters:
localTimeString ( string )

ISO8601 formatted local time string, non UTC

timezone ( string )

Time zone in IANA database format 'Europe/Stockholm'

throwOnInvalidTime ( boolean ) <optional>

Default is to return the adjusted time if the call happens during a Daylight-Saving-Time switch. E.g. Value "01:01:01" is returned if input time is 00:01:01 while one hour got actually skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw an exception instead.

Source:

(static) .toTZ(date, tzStringopt) → {TimePoint}

Converts a date to a specific time zone and returns an object containing year, month, day, hour, (...) and timezone used for the conversion

Please note: If you just want to display date/time in another time zone, use vanilla JS. See the example below.

Parameters:
date ( date )

Input date

tzString ( string ) <optional>

Timezone string in Europe/Stockholm format

Source:
Examples

Example using minitz:

let normalDate = new Date(); // d is a normal Date instance, with local timezone and correct utc representation

tzDate = minitz.toTZ(d, 'America/New_York');

// Will result in the following object:
// {
//  year: 2022,
//  month: 9,
//  day: 28,
//  hour: 13,
//  minute: 28,
//  second: 28,
//  timezone: "America/New_York"
// }

Example using vanilla js:

console.log(
	// Display current time in America/New_York, using sv-SE locale
	new Date().toLocaleTimeString("sv-SE", { timeZone: "America/New_York" }),
);

(static) .tp(year, month, day, hour, minute, second, timezone) → {TimePoint}

Convenience function which returns a TimePoint object for later use in fromTZ

Parameters:
year ( Number )

1970--

month ( Number )

1-12

day ( Number )

1-31

hour ( Number )

0-24

minute ( Number )

0-60

second ( Number )

0-60

timezone ( string )

Time zone in format 'Europe/Stockholm'

Source: