C # DateTime

Source: Internet
Author: User
Tags local time

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.