"Fragment" C # relationship between DateTime time subtraction and time zone,

Source: Internet
Author: User
Tags time zones

"Fragment" C # relationship between DateTime time subtraction and time zone,

This article is just a basic code snippet and goes straight to the conclusion:C # DateTime time subtraction -- it is irrelevant to the time zone and only related to the time value.

 

Running result:

 

Test code:

1 using System; 2 using System. collections. generic; 3 using System. linq; 4 using System. text; 5 6 namespace Temp_20160623 _ Time Zone 7 {8 class Program 9 {10 static void Main (string [] args) 11 {12 DateTime timeNow = DateTime. now; // current local time (Beijing Time + 8) 13 DateTime timeUtcNow = DateTime. utcNow; // world coordination time (Greenwich Mean + 0) 14 DateTime timeUtcNow2 = new DateTime (15 timeUtcNow. year, timeUtcNow. month, timeUtcNow. day, 16 timeUt CNow. hour, timeUtcNow. minute, timeUtcNow. second, timeUtcNow. millisecond, 17 DateTimeKind. local); // world coordination time (Beijing Time + 0) -- Console of Beijing time 18 19 20 with the same UTC time value. writeLine ("Beijing Time + 8:" + timeNow); 21 Console. writeLine ("Greenwich Mean + 0:" + timeUtcNow); 22 Console. writeLine ("Beijing Time + 8:" + timeUtcNow2); 23 24 25 26 // The difference between timeNow and timeUtcNow is 8 time zones 27 // question: How much is the difference between the two time periods? 28 29 30 TimeSpan timeSpan = timeNow-timeUtcNow; 31 Console. writeLine ("({0} + 8)-({1} + 0) = {2}", timeNow, timeUtcNow, timeSpan. totalHours. toString ("F6"); 32 33 TimeSpan timeSpan2 = timeNow-timeUtcNow2; 34 Console. writeLine ("({0} + 8)-({1} + 8) = {2}", timeNow, timeUtcNow2, timeSpan2.TotalHours. toString ("F6"); 35 36 37} 38} 39}

 


As a result, there is such a problem (think only for the following questions ):
> At the beginning, the project was a domestic project-the time zone was never considered, and the + 8 time was used in a unified manner, and the database was saved for + 8 time.
> After that, the project starts to be used across countries-foreign users can also use it.
Q:
> How can we improve the project's support for international time on the premise that the existing changes are minimized?

 

(This article is not a heavyweight technology-small details at the bottom layer. If you miss your time, I am sorry .)

 

Related Article

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.