Original: C # datetime and Timestamp conversions
C # datetime-to-timestamp conversions, including JavaScript timestamps and Unix timestamps.
1. What is a timestamp
The first thing to know is the difference between JavaScript and UNIX timestamps:
JavaScript Timestamp: GMT January 01, 1970 00:00 00 seconds (Beijing time January 01, 1970 08:00 00 seconds) up to now the total number of milliseconds .
Unix Timestamp: GMT January 01, 1970 00:00 00 seconds (Beijing time January 01, 1970 08:00 00 seconds) up to now the total number of seconds .
You can see the total number of milliseconds for the JavaScript timestamp, and the Unix timestamp is the total number of seconds .
Like the same thing. 2016/11/03 12:30:00, converted to a JavaScript timestamp of 1478147400000, and converted to a Unix timestamp of 1478147400.
2. JavaScript timestamps Convert 2.1 C # datetime to JavaScript timestamp
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (New System.DateTime (1970, 1, 1)); local time zone long TimeStamp = (long) (Datetime.now-starttime). TotalMilliseconds; Number of milliseconds System.Console.WriteLine (TimeStamp);
2.2 JavaScript timestamp conversion to C # DateTime
Long jstimestamp = 1478169023479; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (New System.DateTime (1970, 1, 1)); local time zone DateTime dt = starttime.addmilliseconds (Jstimestamp); System.Console.WriteLine (dt. ToString ("Yyyy/mm/dd HH:mm:ss:ffff"));
3. UNIX timestamps convert 3.1 C # datetime to UNIX timestamp
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (New System.DateTime (1970, 1, 1)); local time zone long TimeStamp = (long) (Datetime.now-starttime). TotalSeconds; Number of seconds System.Console.WriteLine (TimeStamp);
3.2 Unix timestamp conversion to C # DateTime
Long unixtimestamp = 1478162177; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime (New System.DateTime (1970, 1, 1)); local time zone DateTime dt = starttime.addseconds (Unixtimestamp); System.Console.WriteLine (dt. ToString ("Yyyy/mm/dd HH:mm:ss:ffff"));
================================== Series article ==========================================
This article: 1.4 C # datetime and Timestamp conversions
C # Article Navigation
C # datetime and Timestamp conversions