Recently in the writing Time service, to get the day's 0 points this time, but this is the acquisition of
Copy Code code as follows:
DateTime dt = DateTime.Parse (DateTime.Now.ToString ("yyyy-mm-dd") + "00:00:00");
Console.WriteLine (dt. ToString ("Yyyy-mm-dd HH:mm:ss"));
In the local, testing, QA environment test is no problem, but on the public network server, this time service, there is a problem, wrote the next log, unexpectedly found to get the day's 0 points, after the acquisition is the previous 0 points, the original server time is 12 hours, the local environment is 24 hours system.
Continue to delve into, found every day from 00:00:00 to 00:59:59 this time, in the 24-hour time is the date of the day, but in the 12-hour time, the day before yesterday's date of 12:00:00 to 12:59:59. For example, according to the 24-hour time, today's "2013-09-26 00:00:00" This time, in the 12-hour server, get words is "2013-09-25 12:00:00", DateTime.Now.ToString (" Yyyy-mm-dd ") This method obtains the date is" 2013-09-25 ", then the DT obtains is" 2013-09-25 12:00:00 ".
It turns out that, depending on how many hours of time you get in C #, you can get
Copy Code code as follows:
24-hour System:
DateTime dt = DateTime.Now;
String dt24 = dt. ToString ("Yyyy-mm-dd HH:mm:ss");
12-hour System:
DateTime dt = DateTime.Now;
String dt12 = dt. ToString ("Yyyy-mm-dd hh:mm:ss");
is determined by the case of H.
Regardless of whether the server's time system is 12 hours or 24 hours, capital H gets 24 hours, and lowercase h gets a 12-hour time.