12-hour system and 24-hour system to get the day 0 points of the problem discussion _ Practical skills

Source: Internet
Author: User

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.

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.