What is UTC time and how to convert to UTC time

Source: Internet
Author: User

Analyze problems

UTC is actually the Greenwich Mean Time (GMT). It is measured at 0 degrees longitude. The local time in each region has a fixed time difference with UTC time, the local time in those regions is the effect of UTC time, time difference, and time difference.

As described in the previous sections of this book, the 64-bit long integer used to store time in datetime only uses 62 lower bits to represent time, while the two higher bits represent enumeration. The kind attribute of datetime exposes this flag, and the kind Code better illustrates this feature:

 

In many cases, the local time and UTC time need to be converted to each other. The datetime structure provides the touniversaltime and tolocaltime methods, which not only change the storage time, but also change the kind flag. The following code shows how to use these two methods.

Using system; namespace test {class utclocal {static void main () {datetime date = datetime. now; console. writeline ("current local time: {0}", date. tostring (); console. writeline ("kind flag: {0}", date. kind. tostring (); // convert to UTC time datetime newdate = date. touniversaltime (); console. writeline ("converted to UTC time: {0}", newdate. tostring (); console. writeline ("New Kind flag: {0}", newdate. kind. tostring (); // convert to the local time datetime backdate = newdate. tolocaltime (); console. writeline ("back to local time: {0}", backdate. tostring (); console. writeline ("converted kind flag: {0}", backdate. kind. tostring (); console. read ();}}}

As you can see, the operation of the two methods is very simple, but do not ignore the changes to the logo of the two methods. The following is the execution result of the program.

Note:

The conversion between the local time and the UTC time will take into account the timeout time.

Answer

UTC is the Greenwich Mean Time (GMT), which is the time measured at 0 degrees of precision. The touniversaltime and tolocaltime methods can be used to convert between the local time and the UTC time. During the conversion, the two methods will correspondingly set the high two-digit mark of the 64-bit integer that saves the time, and the conversion algorithm considers the limit.

 

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.