Skip to content

Commit f7fbe9a

Browse files
committed
New: large integer in JavaScript representing time in milliseconds, you can convert it to a readable date and time format using the
1 parent cac5e1d commit f7fbe9a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

basic/integer_to_time.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Assume you have a big integer for time in milliseconds
2+
const bigIntTime = 1672531199000n; // JavaScript BigInt, for example
3+
4+
// Convert BigInt to regular number if it's safe (less than MAX_SAFE_INTEGER)
5+
const timeInMilliseconds = Number(bigIntTime);
6+
7+
// Create a Date object from the milliseconds
8+
const date = new Date(timeInMilliseconds);
9+
10+
// Format the date to a readable format
11+
const formattedDate = date.toISOString(); // "2023-01-01T00:59:59.000Z"
12+
13+
console.log(formattedDate);
14+

0 commit comments

Comments
 (0)