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.