Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A light and fast package to lookup timezones, get current datetime in any timezone, convert datetime timezones from utc to another timezone or vica-versa.

License

NotificationsYou must be signed in to change notification settings

Anmol53/timezones

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

A light and fast package to lookup timezones, get current datetime in any timezone, convert datetime timezones from utc to another timezone or vica-versa.

Usage

Just import the timezones package.

consttimezones=require("timezones")

Methods

Examples

getAllTimezoneDetails()

  • Will return all the available timezones, their abbreviation and their utc_offset.
  • No Parameters
  • Example:
constallTimezones=timezones.getAllTimezoneDetails();console.log(allTimezones);/*Output:[    { zone: 'Africa/Abidjan', abbreviation: 'GMT', utc_offset: '+00:00' },    { zone: 'Africa/Accra', abbreviation: 'GMT', utc_offset: '+00:00' },    { zone: 'Africa/Algiers', abbreviation: 'CET', utc_offset: '+01:00' },    { zone: 'Africa/Bissau', abbreviation: 'GMT', utc_offset: '+00:00' },    { zone: 'Africa/Cairo', abbreviation: 'EET', utc_offset: '+02:00' },    ... more items]*/

getTimezoneDetails()

  • Will return timezones, it's abbreviation and utc_offset.
  • Parameters:
    • timezone(required)
  • Examples:
//Example 1consttimezoneDetails=timezones.getTimezoneDetails("Africa/Cairo");console.log(timezoneDetails);/*Output:{  status: 'OK',  zone: 'Africa/Cairo',  abbreviation: 'EET',  utc_offset: '+02:00'}*/
//Example 2consttimezoneDetails=timezones.getTimezoneDetails("Abc");console.log(timezoneDetails);/*Output:{    status: 'Zone Not Found'}*/
//Example 3consttimezoneDetails=timezones.getTimezoneDetails();console.log(timezoneDetails);/*Output:{    status: 'Invalid call: timezone is required field'}*/

getOffset()

  • Will return utc_offset of required timezone.
  • Parameters:
    • timezone(required)
  • Examples:
//Example 1constoffset=timezones.getOffset("Asia/Oral");console.log(offset);/*Output:{    status: 'OK',    utc_offset: '+05:00'}*/
//Example 2constoffset=timezones.getOffset("Abc");console.log(offset);/*Output:{    status: 'Zone Not Found'}*/
//Example 3constoffset=timezones.getOffset();console.log(offset);/*Output:{    status: 'Invalid call: timezone is required field'}*/

convertFromUTC()

  • Will return date (in ISO Format) in required timezone.
  • Parameters:
    • date(required) Must be a JS Date
    • utc_offset
    • zone
  • Note: If both utc_offset and zone are not passed, function will just formatdate to ISO format and return it.
  • Examples:
//Example 1constrequired_date=timezones.convertFromUTC();console.log(required_date);/*Output:{    status: 'Invalid Date'}*/
//Example 2constrequired_date=timezones.convertFromUTC({date :"2022/11/06"});console.log(required_date);/*Output:{    status: 'Invalid Date'}*/// Reason: Date is not an JS Date
//Example 3constinputDate=newDate("Wed May 18 2022 21:38:17 GMT+0000");constrequired_date=timezones.convertFromUTC({date :inputDate});console.log(required_date);/*Output:{    status: 'OK',    iso_date: '2022-05-18T21:38:17.000Z'}*/
//Example 4constinputDate=newDate("Wed May 18 2022 21:38:17 GMT+0000");constrequired_date=timezones.convertFromUTC({date :inputDate,utc_offset :"abc"});console.log(required_date);/*Output:{    status: 'Invalid Offset',}*/
//Example 5constinputDate=newDate("Wed May 18 2022 21:38:17 GMT+0000");constrequired_date=timezones.convertFromUTC({date :inputDate,utc_offset :"+05:30"});console.log(required_date);/*Output:{    status: 'OK',    iso_date: '2022-05-19T03:08:17.000+05:30'}*/
//Example 6constinputDate=newDate("Wed May 18 2022 21:38:17 GMT+0000");constrequired_date=timezones.convertFromUTC({date :inputDate,zone :"Australia/Sydney"});console.log(required_date);/*Output:{    status: 'OK',    iso_date: '2022-05-19T07:38:17.000+10:00'}*/
//Example 7constinputDate=newDate("Wed May 18 2022 21:38:17 GMT+0000");constrequired_date=timezones.convertFromUTC({date :inputDate,zone :"Australia/Sydney",utc_offset :"+09:00"});console.log(required_date);/*Output:{    status: 'utc_offset does not matched with zone'}*/
//Example 8constinputDate=newDate("Wed May 18 2022 21:38:17 GMT+0000");constrequired_date=timezones.convertFromUTC({date :inputDate,zone :"Australia/Sydney",utc_offset :"+10:00"});console.log(required_date);/*Output:{    status: 'OK',    iso_date: '2022-05-19T07:38:17.000+10:00'}*/

convertToUTC()

  • Will return date (in ISO Format) in UTC timezone from passed timezone.
  • Parameters:
    • date(required) Must be a JS Date
  • Examples:
//Example 1constrequired_date=timezones.convertToUTC();console.log(required_date);/*Output:{    status: 'Invalid Date'}*/
//Example 2constrequired_date=timezones.convertToUTC({date :"2022/11/06"});console.log(required_date);/*Output:{    status: 'Invalid Date'}*/// Reason: Date is not an JS Date
//Example 3constinputDate=newDate("Wed May 18 2022 21:38:17 GMT+0530");constrequired_date=timezones.convertToUTC({date :inputDate});console.log(required_date);/*Output:{    status: 'OK',    iso_date: '2022-05-18T16:08:17.000Z'}*/

getCurrentDateTime()

  • Will return date (in ISO Format) in required timezone.
  • Parameters:
    • utc_offset
    • zone
  • Note: If both utc_offset and zone are not passed, function will return UTC datetime.
  • Examples:
//Example 1constrequired_date=timezones.getCurrentDateTime();console.log(required_date);/*Output:{    status: 'OK',    iso_date: '2022-08-27T09:27:49.146Z'}*/
//Example 2constrequired_date=timezones.getCurrentDateTime({utc_offset :"abc"});console.log(required_date);/*Output:{    status: 'Invalid Offset',}*/
//Example 3constrequired_date=timezones.getCurrentDateTime({utc_offset :"+05:30"});console.log(required_date);/*Output:{    status: 'OK',    iso_date: '2022-08-27T14:57:49.146+05:30'}*/
//Example 4constrequired_date=timezones.getCurrentDateTime({zone :"Australia/Sydney"});console.log(required_date);/*Output:{    status: 'OK',    iso_date: '2022-08-27T19:27:49.146+10:00'}*/
//Example 5constrequired_date=timezones.getCurrentDateTime({zone :"Australia/Sydney",utc_offset :"+09:00"});console.log(required_date);/*Output:{    status: 'utc_offset does not matched with zone'}*/
//Example 6constrequired_date=timezones.getCurrentDateTime({zone :"Australia/Sydney",utc_offset :"+10:00"});console.log(required_date);/*Output:{    status: 'OK',    iso_date: '2022-08-27T19:27:49.146+10:00'}*/

License

MIT License

Copyright (c) 2022 Anmol Agrawal

Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.

Author

Anmol Agrawal

Mail ID |LinkedIn |GitHub |LeetCode |CodeChef |HackerRank

"Any suggestions would be appreciated"

About

A light and fast package to lookup timezones, get current datetime in any timezone, convert datetime timezones from utc to another timezone or vica-versa.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp