Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
Can someone tell me how to convert DateTime64(6,UTC) into Date or readable string in javascript. Let's suppose I have Int64 value 637453206453037910 (precision 6, UTC) so how to convert
637453206453037910
in the proper datetime string.
Thanks,

What I have tried:

console.log(new Date(637453206453037910))
Posted
Updated 31-Mar-21 5:20am

1 solution

Quote:
JavaScript stores dates as number of milliseconds since January 01, 1970, 00:00:00 UTC (Universal Time Coordinated).
So you need to subtract the number of ticks between Jan 1 0000 and Jan 1 1970 and then convert the result into milliseconds.

JavaScript
// NB a tick is commonly 100 nanoseconds 
var epoch = 621355968000000000;   // ticks up to Jan 1 1970
var tdate = 637453206453037910;   // the date in ticks
var dt = td - epoch;              // rebase to Jan 1 1970
var millisec = dt / 10000;        // convert to milliseconds
var d = new Date(millisec);       // create a Javascript Date object
 
Share this answer
 
v3
Comments
zeeShan anSari 31-Mar-21 18:01pm    
Nice explanation...Its work. thanks!
Maciej Los 1-Apr-21 6:47am    
5ed!
Richard MacCutchan 1-Apr-21 7:02am    
Thanks. Fortunately .NET made it easy to find the answer.
zeeShan anSari 19-Apr-21 11:56am    
It converts up to 3 precision but I need up to 6 precision. What should I do.
Richard MacCutchan 19-Apr-21 12:20pm    
Sorry, I do not understand.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900