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.
The JavaScript Date type's origin is the Unix epoch: midnight on 1 January 1970.
The .NET DateTime type's origin is midnight on 1 January 0001.
You can translate a JavaScript Date
object to .NET ticks as follows:
var yourDate = new Date(); // for example
// the number of .net ticks at the unix epoch
var epochTicks = 621355968000000000;
// there are 10000 .net ticks per millisecond
var ticksPerMillisecond = 10000;
// calculate the total number of .net ticks for your date
var yourTicks = epochTicks + (yourDate.getTime() * ticksPerMillisecond);