Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10352770
get-datetime.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
get-datetime.js
View Options
"use strict"
;
const
dateFormatters
=
{
"yyyy-mm-dd"
:
date
=>
date
.
toISOString
().
split
(
"T"
)[
0
],
};
const
timeFormatters
=
{
"hh:mm:ss"
:
parsed_time
=>
parsed_time
.
substring
(
0
,
8
),
"hh:mm:ss.mmm"
:
parsed_time
=>
parsed_time
.
slice
(
0
,
-
1
),
};
const
dateFormats
=
Object
.
keys
(
dateFormatters
);
const
timeFormats
=
Object
.
keys
(
timeFormatters
);
function
getTimeOfNow
()
{
return
getDateTime
(
new
Date
(),
"hh:mm:ss.mmm"
);
}
function
getNow
()
{
return
getDateTime
(
new
Date
(),
"yyyy-mm-dd hh:mm:ss.mmm"
);
}
function
getDateTime
(
date
,
format_string
=
"yyyy-mm-dd hh:mm:ss"
)
{
const
formats
=
format_string
.
split
(
" "
);
return
formats
.
reduce
((
date_string
,
format
)
=>
{
if
(
dateFormats
.
includes
(
format
))
{
return
date_string
+
" "
+
dateFormatters
[
format
](
date
);
}
else
if
(
timeFormats
.
includes
(
format
))
{
const
parsed_time
=
date
.
toISOString
().
split
(
"T"
)[
1
];
return
date_string
+
" "
+
timeFormatters
[
format
](
parsed_time
);
}
else
{
throw
new
Error
(
"Unknown format: "
+
format
);
}
},
""
)
.
trimLeft
();
}
module
.
exports
=
{
getTimeOfNow
,
getNow
,
getDateTime
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 2, 19:49 (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1030495
Default Alt Text
get-datetime.js (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment