ASP.NET timestamp (TimeStamp) each conversion and time (DateTime) of

Transfer to: https://www.cnblogs.com/smallshu/p/9264451.html  

  What is the time stamp: time stamp refers GMT January 1, 1970 00 hours 00 minutes 00 seconds (Beijing time on January 1, 1970 08 hours 00 minutes 00 seconds) until now the total number of seconds.

  Online conversion timestamp URL: https: //tool.lu/timestamp, timestamp conversion URL There are many, as well as webmaster tools frequently used.

Lower attachment code based paste can be used to start the console, to be a reference (using System) namespace;

 

/// <Summary> 
/// stamp taken, where there is a highly concurrent repeat. Want to solve this problem, please use sleep thread to sleep for 1 millisecond. 
/// </ Summary> 
/// <param name = "AccurateToMilliseconds"> to the millisecond </ param> 
/// <Returns> returns a long integer timestamp </ Returns> 
public static Long getTimestamp (BOOL to false AccurateToMilliseconds = ) 
{ 
  IF (AccurateToMilliseconds) 
  { // use the current number of time ticks (636662920472315179) minus 1 January 1970 ticks (621355968000000000) is removed (deleted) counts back 4 (after time unit is less than four milliseconds, Do not approaching) and then rounding (to the decimal point). 
    // Note: DateTime.Now.ToUniversalTime can not be abbreviated to DateTime.Now.Ticks, there will be several hours of errors. 
    // ticks = 621355968000000000 calculation Long (new new the DateTime (1970,. 1,. 1,. 8, 0, 0)) the ToUniversalTime () Ticks;.. 
    Return (. DateTime.Now.ToUniversalTime () Ticks - 621355968000000000) / 10000;

    





    The above are // millisecond accuracy, it is necessary to remove the last (10000), here only accurate to the second, plus three to 0 (1 second equals 1000 mm) long 10000 later. 
    return (DateTime.Now.ToUniversalTime () Ticks - 621355968000000000.) / 10000000; 
  } 
}

 

/// <the Summary> 
/// timestamp inverted to time, there are a lot of flip method, however, do not use too string (string) to operate, we all know that the string will be very slow! 
/// </ Summary> 
/// <param name = "TimeStamp"> timestamp </ param> 
/// <param name = "AccurateToMilliseconds"> whether the precision of milliseconds </ param> 
/// <Returns> Back a date time </ Returns> 
public static the dateTime the GetTime (Long TimeStamp, BOOL = AccurateToMilliseconds to false) 
{ 
  System.DateTime the startTime = TimeZone.CurrentTimeZone.ToLocalTime (new new System.DateTime (1970,. 1,. 1)); // local time zone 
  if (AccurateToMilliseconds) 
  { 
    return startTime.AddTicks (TimeStamp * 10000); 
  } 
  the else 
  { 
    return startTime.AddTicks (TimeStamp 10000000 *); 
  } 
}

Guess you like

Origin www.cnblogs.com/MonkeyDWang/p/11118461.html