Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert JavaScript date object to ticks

Tags:

javascript

c#

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.

like image 591
Talha Avatar asked Nov 01 '11 12:11

Talha


People also ask

How long is a tick in JavaScript?

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.

What is JavaScript date object?

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.

How does JavaScript dates in objects of data type?

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.


Video Answer


1 Answers

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.

like image 153
Sheikh Ali Avatar answered Sep 27 '22 18:09

Sheikh Ali