1.0.1 • Published 2 years ago

world-timestamp v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

world-timestamp

Provides UTC (or any timezone) time in microseconds and milliseconds from https://worldtimeapi.org.

  • Totally independent of the local system clock.
  • Capable of next.js, nuxt.js or any react projects.
  • Supports various timezones. (See worldtimeapi/timezones)

Installation

$ npm install world-timestamp

Usage

import worldTimestamp from 'world-timestamp';

const getUTCTimestamp = async () => {
    // const timestamp = await worldTimestamp(); // "Etc/UTC" as default
    const timestamp = await worldTimestamp("Asia/Tokyo");

    console.log(timestamp.response); // returns worldtimeapi.org response
    console.log(timestamp.response.datetime); // Ex. 2022-10-01T18:00:00.123456+09:00

    console.log(timestamp.milliseconds); // 1664614800123.456
    console.log(timestamp.utcMilliseconds); // 1664647200123.456

    console.log(timestamp.microseconds); // 1664614800123456
    console.log(timestamp.utcMicroseconds); // 1664647200123456
};

References

worldTimestamp(timezone?: string): Promise\<WorldTimestamp>

ParameterTypeDescription
timezonestringTimezone. Default: "Etc/UTC"

You can find all available timezones here: https://worldtimeapi.org/timezones

WorldTimestamp

PropertyTypeDescription
responseWorldTimeApiResponseWorldtimeapi.org response
millisecondsnumberTimestamp in milliseconds
utcMillisecondsnumberTimestamp in milliseconds in UTC
microsecondsnumber(intager)Timestamp in microseconds
utcMicrosecondsnumber(intager)Timestamp in microseconds in UTC

WorldTimeApiResponse

PropertyTypeDescription
abbreviationstringAbbreviation of the timezone
client_ipstringClient IP address
datetimestringTimestamp in ISO 8601 format
day_of_weeknumberDay of the week
day_of_yearnumberDay of the year
dstbooleanIs daylight saving time in effect?
dst_fromstringDate daylight saving time starts
dst_offsetnumberDaylight saving time offset
dst_untilstringDate daylight saving time ends
raw_offsetnumberTimezone offset from UTC including daylight saving time
timezonestringTimezone
unixtimenumberTimestamp in seconds
utc_datetimestringTimestamp in ISO 8601 format in UTC
utc_offsetstringTimezone offset from UTC
week_numbernumberWeek number

see more in https://worldtimeapi.org/pages/schema

License

MIT License © 2022 MugiSus

Feel free to contact me if you have any questions or suggestions.