让代码运行在不同国家环境下,都能准确获得指定国家的时间!Let the code run in different national environments, you can accurately obtain the time of the specified country!
Installations
npm install @time-zone/date
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
12.22.7
NPM Version
6.14.15
Score
71.1
Supply Chain
98.8
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Oumae-Kumiko
Download Statistics
Total Downloads
4,496
Last Day
3
Last Week
18
Last Month
63
Last Year
1,601
GitHub Statistics
26 Stars
12 Commits
5 Forks
5 Watchers
1 Branches
1 Contributors
Updated on Nov 08, 2024
Bundle Size
606.00 B
Minified
370.00 B
Minified + Gzipped
Package Meta Information
Latest Version
2.2.2
Package Id
@time-zone/date@2.2.2
Unpacked Size
36.86 kB
Size
8.58 kB
File Count
8
NPM Version
6.14.15
Node Version
12.22.7
Total Downloads
Cumulative downloads
Total Downloads
4,496
Last Day
0%
3
Compared to previous day
Last Week
157.1%
18
Compared to previous week
Last Month
-22.2%
63
Compared to previous month
Last Year
19.4%
1,601
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads

No dependencies detected.
Get the tool library of time zones and times in the world
Preface
- Let the code run in different national environments, you can accurately obtain the time of the specified country!
English | 简体中文
Installation
1npm i @time-zone/date --save
Example
- All APIs are introduced in the same way
- Total 31 APIs
1import {isUS_Wt,isUS_Dst,getWorldTimeZone,getUTCDate} from '@time-zone/date' 2isUS_Wt() // true: It's winter time in the United States GMT-5 ; false: You know... 3getUTCDate() // UTC Current time 4getUTCDate("2022-2-1") 5getUTCDate("2022-2-1 13:10:10") 6getWorldTimeZone() 7getWorldTimeZone("2022-2-1 13:10:10",'en-US') 8getWorldTimeZone("2022-2-1 13:10:10",'en-US',{timeZone:'America/New_York'}) // Specify the time corresponding to a time zone 9getWorldTimeZone(null,'en-US',{timeZone:'America/New_York'}) // Time zone current time 10getWorldTimeZone(new Date(),'en-US',{timeZone:'America/New_York'}) // Time zone current time 11getWorldTimeZone(1643692210000)
Referral function
-
Determine whether the United States is now in winter time
-
Judge whether the United States is now daylight saving time
-
Gets the time in the specified time zone
- Full time
- Full time format adjustment
- yyyymmdd | ddmmyyyy | mmddyyyy
- Custom year and month and date formats: order, separator
- hhmmss
- year
- month
- date
- hours(24-hour system)
- minutes
- seconds
- week
In addition, the above method can replace all the following contents
-
Get EST time zone
- Full time
- yyyymmdd
- hhmmss
- yearv
- month
- date
- hours(24-hour system. You can set 0 as the starting point of a new day or 24 as the starting point of a new day)
- minutes
- seconds
- week
-
Get UTC time zone: time difference ± 0
- Full time
- year
- month
- date
- hours
- minutes
- seconds
API
getWorldTimeZone()
As mentioned at the beginning of the introduction, this is the main API .
See the end of the document for references tolocales
andoptions
parameters.
- Gets the time in the specified time zone. The first parameter is the returned language type and the second parameter is the target time zone
- 3 parameters
date
- purpose:
Specify the time to get, and the default current time will not be transferred
- type:
?:string | number | Date | null | undefined
- value:
Those that match the first parameter of 'new date()' can be used, and 'null' and 'undefined' represent the current time.
- purpose:
locales
- purpose:
Returns the corresponding language type
- type:
?:string
- value:
language[-scripts][-region]
- purpose:
options
- purpose:
Adjust the returned time format content. Specifies the time to return to the time zone
- type:
?:object
- value:
See options parameter below
- purpose:
1import { getWorldTimeZone } from '@time-zone/date' 2// Get the full time of the target time zone 3let date = getWorldTimeZone(new Date(),'en-US',{timeZone:'America/New_York'}) 4 5// If it is not transmitted, the current time zone of the code running environment will be the default 6// getWorldTimeZone()
custom_yyyymmdd_sort()
Get the month, year and day of the specified time zone, and you can customize the order of month, year and day (supplement 0 when month and day are single digits)
- 4 parameters
timeZone
:typestring
- Date sequence:type
string
- 1、Must be lowercase。
- 2、The letter is :
y
、m
、d
。 - 3、The default value for parameters not transmitted isyyyymmdd
- The order of 3 letters determines the order of return
- Separator, not passed, default to
/
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { custom_yyyymmdd_sort } from '@time-zone/date' 2let ymd = custom_yyyymmdd_sort('Asia/Shanghai','ymd','-',new Date()) 3let dmy = custom_yyyymmdd_sort('Asia/Shanghai','dmy','/') 4let ydm = custom_yyyymmdd_sort('Asia/Shanghai','ydm','*-@#$$%^^*&(*&)(_+`~') 5let mdy = custom_yyyymmdd_sort('Asia/Shanghai','mdy') 6 7// The month, year and day can be combined arbitrarily, and if there is a repetition, the returned result will also appear repeatedly 8let ymdy = custom_yyyymmdd_sort('Asia/Shanghai','ymdy')
get_mmddyyyy() get_ddmmyyyy() get_yyyymmdd()
Get the month, day and year of the specified time zone (supplement 0 if the month and day are single digits)
- 3 Parameters
timeZone
:typestring
- Separator, not passed, default to
/
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { get_mmddyyyy,get_ddmmyyyy,get_yyyymmdd } from '@time-zone/date' 2let mdy = get_mmddyyyy('Asia/Shanghai','/', new Date()) 3// get_ddmmyyyy() , get_yyyymmdd() 4// No explanation, just look at the name to know the order. 5
custom_ymd_sort()
- 0 will not be added if the month day is a single digit
- Other contents follow
custom_ yyyymmdd_ Sort()
consistent, no further explanation
1import { custom_ymd_sort } from '@time-zone/date' 2let ymd = custom_ymd_sort( 'Asia/Shanghai','ymd','-',new Date() )
get_hms()
- Gets the hour, minute, and second of the target time zone
- 2 parameters
timeZone
:typestring
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { get_hms } from '@time-zone/date' 2let hms = get_hms('Asia/Shanghai') // format:08:00:00
getYear()
- Gets the year of the target time zone
- 2 parameters
timeZone
:typestring
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { getYear } from '@time-zone/date' 2let year = getYear('Asia/Shanghai') // Return value number type
getMonth()
- Gets the month (0-11) of the target time zone
- 2 parameters
timeZone
:typestring
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { getMonth } from '@time-zone/date' 2let month = getMonth('Asia/Shanghai') // Return value number type
getDate()
- Gets the day of the target time zone
- 2 parameters
timeZone
:typestring
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { getDate } from '@time-zone/date' 2let date = getDate('Asia/Shanghai') // Return value number type
getHours()
- Gets the hour of the target time zone
- Get the hours of the target time zone separately, and the unified return value is: '0-23', so as to avoid confusion caused by the problem of 1-24 in the United States.
- 2 parameters
timeZone
:typestring
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { getHours } from '@time-zone/date' 2let hours = getHours('Asia/Shanghai') // Return value number type
getMinutes()
- Gets the minutes of the target time zone
- 2 parameters
timeZone
:typestring
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { getMinutes } from '@time-zone/date' 2let minutes = getMinutes('Asia/Shanghai') // Return value number type
getSeconds()
- Gets the second of the target time zone
- 2 parameters
timeZone
:typestring
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { getSeconds } from '@time-zone/date' 2let sec = getSeconds('Asia/Shanghai') // Return value number type
getDay()
- Gets the week in the target time zone
- The return value is' 0-6 ', 0 is Sunday, 1 is Monday, followed by order
- 2 parameters
timeZone
:typestring
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
1import { getDay } from '@time-zone/date' 2let day = getDay('Asia/Shanghai') // Return value number type
getESTDate()
- Get the time of EST time zone. The returned language type is en US
- parameter
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
- Specified time: the default current time is not transmitted; Parameter type is
1import { getESTDate } from '@time-zone/date' 2let date = getESTDate()
getUTCDate()
- Get UTC time zone
- parameter
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
- Specified time: the default current time is not transmitted; Parameter type is
1import { getUTCDate } from '@time-zone/date' 2let date = getUTCDate()
isUS_Dst()
Judge whether the United States is now daylight saving time
- No parameters.
- Returning 'true' indicates that the United States is currently daylight saving time
- Return value:
true
|false
1import { isUS_Dst } from '@time-zone/date' 2let booleanDate = isUS_Dst()
isUS_Wt()
Determine whether the United States is now in winter time
- No parameters.
- Returning 'true' indicates that it is winter time in the United States
- Return value:
true
|false
1import { isUS_Wt } from '@time-zone/date' 2let booleanDate = isUS_Wt()
Other
Corresponding value of EST time
- parameter
- Specified time: the default current time is not transmitted; Parameter type is
?:string | number | Date | null | undefined
- Specified time: the default current time is not transmitted; Parameter type is
1import { getESTmmddyyyy, ...... } from '@time-zone/date' 2getESTmmddyyyy() 3getESThms() 4EST_getYear() 5EST_getMonth() 6EST_getDate() 7EST_getHours(0) // U.S. hours. If 0 is passed, it means that the starting point of the new day is 0, otherwise it is 24 8EST_getMinutes() 9EST_getSeconds() 10EST_getDay()
locales
parameter
- type:
string
- language[-scripts][-region]
- The special code can be replaced by the corresponding code type. Refer to the MDN website for details
- language[-scripts][-region]-u-nu-*
- language[-scripts][-region]-u-ca-*
- reference value
- Refer to for other values:http://www.lingoes.cn/zh/translator/langcode.htm
1"zh-Hans" //Simplified Chinese 2"zh-TW" //Traditional Chinese 3"ru-RU" //Russian 4"en-GB" //britain 5"it-IT" //Italy 6"fr-FR" //French 7"pt-PT" //Portugal 8"de-DE" //German 9"en-US" //usa 10"en-AU" //澳大利亚 11"en-CA" //Australia 12"ko-KR" //the republic of korea 13"ar-EG" //arab 14"ja-JP" //Japan 15"nl-NL" //Netherlands 16"es-ES" //Spain 17"hi-IN" //Hindi 18"eo" //Esperanto
options
parameter
-
type:
object
-
The built-in default parameter is
1const DEFAULT_OPTIONS = { 2 year: "numeric", 3 month: "numeric", 4 day: "numeric", 5 hour: "numeric", 6 minute: "numeric", 7 second: "numeric", 8 weekday: "short", 9 hour12:false, 10 timeZoneName :"short", 11}
Configurable parameters. If they have the same properties as the default parameters, the passed in parameters will prevail
1let options = { 2 era: "long", //Show ad:"narrow", "short", "long" 3 year: "numeric", //"numeric", "2-digit" 4 month: "numeric", //"numeric", "2-digit", "narrow", "short", "long" 5 day: "numeric", //"numeric", "2-digit" 6 hour: "numeric", //"numeric", "2-digit" 7 minute: "numeric",//"numeric", "2-digit" 8 second: "numeric",//"numeric", "2-digit" 9 weekday: "long", //"narrow", "short", "long" 10 hour12:false, // true | false 11 timeZoneName :"short", //"short", "long" 12 timeZone:"", // Specify the time zone for the city 13}
Reference value of:options.timeZone
- For other values, please refer to:https://www.iana.org/time-zones
1timeZone:'UTC' // UTC time 2timeZone:'Europe/Berlin' // GMT+1; German time zone 3timeZone:'Australia/Sydney' // GMT+11; Australian time zone 4timeZone:'Europe/Moscow' // GMT+3; Russian time zone 5timeZone:'Europe/Paris' // GMT+1; French time zone 6timeZone:'Europe/London' // GMT; UK time zone 7timeZone:'Asia/Tokyo' // JST; Tokyo time zone 8timeZone:'Asia/Shanghai' // GMT+8; Beijing time zone 9timeZone:'America/Denver' // MST; Us mountain time zone 10timeZone:'America/Los_Angeles' // PTZ; Pacific time zone 11timeZone:'America/New_York' // EST; Eastern time zone 12timeZone:'America/Chicago' // CST; Central time zone
Version update history
v2.2.2
Update document parameter description
v2.2.1
Update document example reference
v2.2.0
The corresponding time can be specified for all API additions
v2.1.2
Verification of development and production environment
v2.1.1
add tsconfig.json
v2.1.0
Change the JS of the library to ts

No vulnerabilities found.

No security vulnerabilities found.
Gathering detailed insights and metrics for @time-zone/date