Problems .NET timestamp offset, UTC and GMT

Convert.ToInt64(DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds);

Use this code to get the timestamp usually 8 hours earlier than the actual time, we guess the reason may be new DateTime (1970,1,1) actually get is the return of Beijing, the value that is UTC + 8.
GMT is the standard time stamp to 8 hours, summary, time stamps are correct code is as follows

Convert.ToInt64(DateTime.UTCNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds);

Get the right time

Released three original articles · won praise 0 · Views 166

Guess you like

Origin blog.csdn.net/m0_46059204/article/details/104335432