GetTime in JS is similar to DateTime. Ticks in. Net, so the two concepts need to be used for mutual conversion. However, getTime and Ticks have different meanings. See the following definitions:
GetTime definition in JS:
The getTime () method returns the number of milliseconds from January 1, January 1, 1970.
Ticks in C #
The value of this attribute indicates the number of intervals between January 1, 0001 nanoseconds that have elapsed since midnight, January 1, 100.
For a few words, the nanoseconds are also called microseconds. The conversion relationships between them are as follows:
1 second = 10 ^ 3 ms
1 millisecond = 10 ^ 3 microseconds
1 microsecond = 10 ^ 3 microseconds
After viewing the definition of getTime and Ticks, we can know that getTime is in milliseconds, and Ticks is in 100 nanoseconds. Therefore, the difference between getTime and Ticks is 1000*1000/100. getTime () since-1-1 and-1, Ticks starts from-1-1. Therefore, Ticks has an additional time before-1. The conversion formula is as follows:
GetTime () * 1000*1000/100 + DateTime. Parse ("1970-1-1"). Ticks
The test procedure is as follows:
// JS time conversion. net time long jsGetTime = 1247617999000; Console. writeLine (jsGetTime); long jsBeginTick = DateTime. parse ("1970-1-1 "). ticks; long netTicks = jsGetTime * 1000*10 + jsBeginTick; DateTime dt = new DateTime (netTicks); Console. writeLine (dt. toString ("yyyy-MM-dd HH: mm: ss"); DateTime dt2 = dt. toLocalTime (); Console. writeLine (dt2.ToString ("yyyy-MM-dd HH: mm: ss "));//. net Time to JS getTime (); long dt2Ticks = dt2.ToUniversalTime (). ticks; long dt2JsTicks = (dt2Ticks-jsBeginTick)/(1000*10); Console. writeLine (dt2JsTicks); Console. read ();