How should I convert JavaScript date object to ticks? I want to use the ticks to get the exact date for my C# application after synchronization of data.
Expanding on the accepted answer as why 635646076777520000 is added.
Javascript new Date().getTime() or Date.now() will return number of milliseconds passed from midnight of January 1, 1970.
In .NET(source under Remarks sections)
The DateTime value type represents dates and times with values ranging from 00:00:00 (midnight), January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.) in the Gregorian calendar.
621355968000000000 is the value of ticks from midnight Jan 1 01 CE to midnight Jan 1 1970
So, in .NET
Console.Write(new DateTime(621355968000000000))
// output 1/1/1970 12:00:00 AM
Hence to convert javascript time to .Net ticks
var currentTime = new Date().getTime();
// 10,000 ticks in 1 millisecond
// jsTicks is number of ticks from midnight Jan 1, 1970
var jsTicks = currentTime * 10000;
// add 621355968000000000 to jsTicks
// netTicks is number of ticks from midnight Jan 1, 01 CE
var netTicks = jsTicks + 621355968000000000;
Now, in .NET
Console.Write(new DateTime(netTicks))
// output current time