minitz

minitz

new minitz(y, m, d, h, i, s, tz, throwOnInvalidopt) → {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:
y ( Number )

1970--

m ( Number )

1-12

d ( Number )

1-31

h ( Number )

0-24

i ( Number )

0-60 Minute

s ( Number )

0-60

tz ( string )

Time zone in IANA database format 'Europe/Stockholm'

throwOnInvalid ( 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(tp, throwOnInvalidopt) → {date}

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

Parameters:
tp ( TimePoint )

Object with specified timezone

throwOnInvalid ( 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(localTimeStr, tz, throwOnInvalidopt) → {date}

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

Parameters:
localTimeStr ( string )

ISO8601 formatted local time string, non UTC

tz ( string )

Time zone in IANA database format 'Europe/Stockholm'

throwOnInvalid ( 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, tzStropt) → {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 ( d )

Input date

tzStr ( 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:
// {
//  y: 2022,
//  m: 9,
//  d: 28,
//  h: 13,
//  i: 28,
//  s: 28,
//  tz: "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(y, m, d, h, i, s, tz) → {TimePoint}

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

Parameters:
y ( Number )

1970--

m ( Number )

1-12

d ( Number )

1-31

h ( Number )

0-24

i ( Number )

0-60 Minute

s ( Number )

0-60

tz ( string )

Time zone in format 'Europe/Stockholm'

Source: