Timestamp in [. Net] [C #] C ා

Time:2020-11-6

UNIX timestamp, or UNIX time or POSIX time, is a kind of time representation, which is defined asGreenwich mean timeThe total number of seconds since 0:00:00, January 1, 1970 (8:00:00, Beijing time, January 1, 1970).

1tick in C ා is 100 nanoseconds (NS)

  • 1 second (s) = 1000 ms
  • 1 millisecond (MS) = 1000 microseconds (μ s)
  • 1 microsecond (μ s) = 1000 nanoseconds (NS)
  • 1 second (s) = 10000000 ticks
  • 1 MS = 10000 ticks

DateTime.Now.Ticks Is the tick number from 0:00:00:00 on January 1, A.D. to the current time zone, DateTime.UtcNow.Ticks Is the tick number from 0:00:00:00 to Greenwich mean time (UTC + 0) on January 1, 1 A.D.

The timestamp can be obtained by

(long)(DateTime.UtcNow - DateTime.UnixEpoch).TotalMilliseconds
(DateTime.UtcNow.Ticks - 621355968000000000) / 10000000

6213559680 million is the number of ticks from 0:00:00, January 1, 2001 to 0:00:00, January 1, 1970. Dividing by 10000000 is to change the tick into seconds.

To convert a timestamp to Greenwich mean time (UTC + 0) datetime:
new DateTime(timeStamp * 10000).AddTicks(DateTime.UnixEpoch.Ticks)
new DateTime(timeStamp * 10000000 + 621355968000000000)

The method to convert a timestamp to a local time is

new DateTime(timeStamp * 10000000 + 621355968000000000).ToLocalTime()
  • Add to phrase set
     
    • web
    • Create a new word set
  • Copy
  • Add to phrase set
     
    • web
    • Create a new word set
  • Copy
  • Add to phrase set
     
    • web
    • Create a new word set
  • Copy
  • Add to phrase set
     
    • web
    • Create a new word set
  • Copy
  • Add to phrase set
     
    • web
    • Create a new word set
  • Copy
  • Add to phrase set
     
    • web
    • Create a new word set
  • Copy
  • Add to phrase set
     
    • web
    • Create a new word set
  • Copy
  • Add to phrase set
     
    • web
    • Create a new word set
  • Copy