deno.land / x / simple_utility@v0.0.9 / src / date.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*** Since the unixtime that can be handled by the `Date` is in milliseconds, this method output downscaled to 1/1000.* @param date date object for any datetime, if blank output the current datetime.* @return unixtime in seconds.*/export function dateEncode(date?:Date){ return Math.floor((date ?? new Date()).getTime() / 1000);}
/*** Since the unixtime that can be handled by the `Date` is in milliseconds, the argument of this method is internally multiplied by x1000.* @param time unixtime in seconds.* @return date object specified by `time`.*/export function dateDecode(time:number){ return new Date(time * 1000);}
/*** Convert formatted datetime string such as ISO8601 to unixtime.* @param dt formatted datetime string.* @return unixtime in seconds.*/export function dateParse(dt:string){ const [y, mo, d, h, mi, s] = dt.split(/[/ :TZ_.-]/i).map(s => Number(s));
return dateEncode(new Date(y, (mo ?? 1) - 1, d ?? 1, h ?? 0, mi ?? 0, s ?? 0));}
simple_utility

Version Info

Tagged at
a year ago