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.
JavaScript: Date. getTime() : a number, representing the number of milliseconds since midnight January 1, 1970. C#: A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second.
JavaScript Date objects represent a single moment in time in a platform-independent format. Date objects contain a Number that represents milliseconds since 1 January 1970 UTC.
The Date object is an inbuilt datatype of JavaScript language. It is used to work with dates and times. The Date object is created by using new keyword, i.e. new Date(). The Date object can be used date and time in terms of millisecond precision within 100 million days before or after 1/1/1970.
If you want to convert your DateTime
object into universal ticks then use the following code snippet:
var ticks = ((yourDateObject.getTime() * 10000) + 621355968000000000);
There are 10000 ticks in a millisecond. And 621.355.968.000.000.000 ticks between 1st Jan 0001 and 1st Jan 1970.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With