"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 .)