-
Notifications
You must be signed in to change notification settings - Fork 2
/
dateTime.js
44 lines (42 loc) · 1.43 KB
/
dateTime.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
export {getDateTime, toRealDateTime, toUnixDateTimeNow}
function getDateTime(dateTime) {
/* description: this function is for formated datetime data,
formatted like international datetime format: 12hr/AM/PM
Additionally use timeZone:"Asia/Dhaka"
params: datetime
return: formatted date like 03:45PM 10/2/2019
*/
if (dateTime) {
let date = new Date(dateTime);
let options = {
hour: 'numeric',
minute: 'numeric',
year: 'numeric',
month: 'numeric',
day: 'numeric',
timeZone: 'UTC'
};
return Intl.DateTimeFormat('en-BD', options).format(date)
//format like 10/10/2019 10:20AM
}
}
function toRealDateTime(dateTime) {
/*description: convert unix to real DataTime
than again convert in to expected datetime
formatted like 1/10/2019 10:01AM
params: datetime
return: formatted datetime again call to getDateTime function
to display formatted datetime like 1/10/2019 10:01AM
*/
if (dateTime) {
return getDateTime(Date(dateTime))
}
}
function toUnixDateTimeNow() {
/*description: convert datetime to unix
formatted like 1563044813038
params: datetime
return: formatted datetime like 1563044813038
*/
return new Date().getTime()
}