1.
UTC Universal Time coordinated coordinated, GMT can be considered utc=gmt
2.c# datetime When instantiating a specified datetimekind, at the time of conversion, the default is to convert the kind of the opposite.
3. The UTC time you see on your computer is calculated in seconds from (January 01, 1970 0:00:00).
The UTC time you see is the number of seconds from this point in 1970 to the exact time. This number of seconds is the Unix timestamp.
4. So the UNIX timestamp calculation must be unified time to calculate, such as the local time of 2017-10-27 10:03 of the Unix timestamp, a way to first convert 2017-10-27 10:03 to UTC time Calculation
The other one calculates the corresponding cost time for January 01, 1970 0:00:00
//if datetime is not specified DateTimeKind at instantiation time, when converted to Utctime or localtime, the default is another format//Utctime and GMT are consistent, in secondsDateTime time =NewDateTime ( .,Ten, -,Ten,3,0);//2017-10-27 10:03Console.WriteLine (time. Kind); DateTime Utctime=Time . ToUniversalTime (); Console.WriteLine (utctime);//{2017/10/27 2:03:00}DateTime localtime =Time . ToLocalTime (); Console.WriteLine (localtime);//{2017/10/27 18:03:00}//Calculate local time 2017-10-27 10:03 Unix Timestamp method one: Convert to UTC timeDateTime StartTime =NewDateTime (1970,1,1,0,0,0, DATETIMEKIND.UTC); LongUtctickets = Utctime.ticks-starttime.ticks; //Calculate local time 2017-10-27 10:03 Unix Timestamp method one: Convert to UTC timeDateTime Startlocaltime =Starttime.tolocaltime (); LongLocaltickets = time. Ticks-startlocaltime.ticks; Console.WriteLine (Utctickets==localtickets); //The datetime.ticks is a chronograph, equivalent to 100 nanometers (1 nm seconds equals one-zero seconds), divided by 10000000 when converted into seconds.//The Unix timestamp is the number of seconds that have elapsed since the start of the January 1, 1970 (Midnight of Utc/gmt), regardless of the leap seconds. LongUtcseconds = utctickets/10000000;//1509069780 can be verified with Unix time stamp webmaster Tools//Convert a Unix timestamp to local timeDateTime TT =starttime.addseconds (utcseconds). ToLocalTime (); Console.WriteLine (TT= = time) +":"+ TT);
Output Result:
C # DateTime