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 to. NET Time
Long maid = 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 "));
// Convert. NET Time to JS gettime ();
Long dt2ticks = dt2.touniversaltime (). ticks;
Long dt2jsticks = (dt2ticks-jsbegintick)/(1000*10 );
Console. writeline (dt2jsticks );
Console. Read ();
From:
Http://www.cnblogs.com/jordan2009/archive/2009/08/17/1547875.html
Private long getjstimes ()
{
Datetime dt = datetime. now;
Long dtticks = DT. touniversaltime (). ticks;
Long jsbegintick = datetime. parse ("1970-1-1"). ticks;
Long dtjsticks = (dtticks-jsbegintick)/(1000*10 );
Return dtjsticks;
}
Private datetime todotnettime (long jstime)
{
Long jsbegintick = datetime. parse ("1970-1-1"). ticks;
Long netticks = jstime * 1000*10 + jsbegintick;
Datetime dt = new datetime (netticks );
Datetime dt2 = DT. tolocaltime ();
Return dt2;
}