Javascript gettime method definition and usage
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 Relationship between them is
1 second = 10 ^ 3 ms
1 millisecond = 10 ^ 3 microseconds
1 microsecond = 10 ^ 3 nanoseconds
Now we need to use c # To make this js gettimer effect. First, we need to convert it into a unified unit, and we will convert it into a hundred S.
The next step is to achieve a unified time point, starting from January 1, January 1, 1970. Then, we need to calculate how many nanoseconds have elapsed since January 1, January 1-19, 0001 to January 1, January 1.
The following code shows the constant privatelonglLeft = 621355968000000000;
- Console.WriteLine(DateTime.Parse("1970-1-1").Ticks);
For example, I want to get the number of milliseconds for "2009-7-1508: 33: 19 ".
First convert to UTC time
- DateTimedt1=Convert.ToDateTime("2009-7-1508:33:19").ToUniversalTime();
Then we can get the number of hundred seconds from January 1, January 1, 1970 to that time.
LongSticks = (dt1.Ticks-DateTime. Parse ("1970-1-1"). Ticks)
The final result is to convert the result to js, so the second is converted to millisecond, Sticks/10000000; the final result is 1247617999.
Similarly, if we convert the number of milliseconds to the local time, we will return it. The difference between Beijing and utc is 8 hours. Therefore, we can use ToLocalTime to convert it to the local time to solve the time difference problem.
The following is the Javascript gettime code.
- PrivatelonglLeft=621355968000000000;
- // Convert the number to time
- PublicstringGetTimeFromInt (longltime)
- {
- LongEticks= (Long) (ltime * 10000000) + lLeft;
- DateTimedt=NewDateTime(Eticks). ToLocalTime ();
- Returndt. ToString ();
- }
- // Convert the time to a number
- PubliclongGetIntFromTime (DateTimedt)
- {
- DateTimedt1= Dt. ToUniversalTime ();
- LongSticks= (Dt1.Ticks-lLeft)/10000000;
- ReturnSticks;
- }
- JavaScript class and inheritance: prototype attribute
- JavaScript class and inheritance: this property
- Summary of three + 1 implementation methods of ExtJS Grid Tooltip
- Implementation of JavaScript asynchronous call framework chain
- JQuery-style chained call of JavaScript asynchronous call framework