Gathering detailed insights and metrics for @time-zone/date
Gathering detailed insights and metrics for @time-zone/date
让代码运行在不同国家环境下,都能准确获得指定国家的时间!Let the code run in different national environments, you can accurately obtain the time of the specified country!
npm install @time-zone/date
Typescript
Module System
Node Version
NPM Version
71.1
Supply Chain
98.8
Quality
75.7
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
4,496
Last Day
3
Last Week
18
Last Month
63
Last Year
1,601
26 Stars
12 Commits
5 Forks
5 Watchers
1 Branches
1 Contributors
Updated on Nov 08, 2024
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
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
No dependencies detected.
English | 简体中文
1npm i @time-zone/date --save
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)
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
In addition, the above method can replace all the following contents
Get EST time zone
Get UTC time zone: time difference ± 0
As mentioned at the beginning of the introduction, this is the main API .
See the end of the document for references tolocales
andoptions
parameters.
date
Specify the time to get, and the default current time will not be transferred
?:string | number | Date | null | undefined
Those that match the first parameter of 'new date()' can be used, and 'null' and 'undefined' represent the current time.
locales
Returns the corresponding language type
?:string
language[-scripts][-region]
options
Adjust the returned time format content. Specifies the time to return to the time zone
?:object
See options parameter below
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()
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)
timeZone
:type string
string
y
、m
、d
。/
?: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 the month, day and year of the specified time zone (supplement 0 if the month and day are single digits)
timeZone
:type string
/
?: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_ yyyymmdd_ Sort()
consistent, no further explanation1import { custom_ymd_sort } from '@time-zone/date' 2let ymd = custom_ymd_sort( 'Asia/Shanghai','ymd','-',new Date() )
timeZone
:type string
?:string | number | Date | null | undefined
1import { get_hms } from '@time-zone/date' 2let hms = get_hms('Asia/Shanghai') // format:08:00:00
timeZone
:type string
?:string | number | Date | null | undefined
1import { getYear } from '@time-zone/date' 2let year = getYear('Asia/Shanghai') // Return value number type
timeZone
:type string
?:string | number | Date | null | undefined
1import { getMonth } from '@time-zone/date' 2let month = getMonth('Asia/Shanghai') // Return value number type
timeZone
:type string
?:string | number | Date | null | undefined
1import { getDate } from '@time-zone/date' 2let date = getDate('Asia/Shanghai') // Return value number type
timeZone
:type string
?:string | number | Date | null | undefined
1import { getHours } from '@time-zone/date' 2let hours = getHours('Asia/Shanghai') // Return value number type
timeZone
:type string
?:string | number | Date | null | undefined
1import { getMinutes } from '@time-zone/date' 2let minutes = getMinutes('Asia/Shanghai') // Return value number type
timeZone
:type string
?:string | number | Date | null | undefined
1import { getSeconds } from '@time-zone/date' 2let sec = getSeconds('Asia/Shanghai') // Return value number type
timeZone
:type string
?:string | number | Date | null | undefined
1import { getDay } from '@time-zone/date' 2let day = getDay('Asia/Shanghai') // Return value number type
?:string | number | Date | null | undefined
1import { getESTDate } from '@time-zone/date' 2let date = getESTDate()
?:string | number | Date | null | undefined
1import { getUTCDate } from '@time-zone/date' 2let date = getUTCDate()
Judge whether the United States is now daylight saving time
true
| false
1import { isUS_Dst } from '@time-zone/date' 2let booleanDate = isUS_Dst()
Determine whether the United States is now in winter time
true
| false
1import { isUS_Wt } from '@time-zone/date' 2let booleanDate = isUS_Wt()
?:string | number | Date | null | undefined
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
parameterstring
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
parametertype: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}
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}
options.timeZone
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
Update document parameter description
Update document example reference
The corresponding time can be specified for all API additions
Verification of development and production environment
add tsconfig.json
Change the JS of the library to ts
No vulnerabilities found.
No security vulnerabilities found.