Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the problem of 12-hour system and 24-hour system to obtain the zero of the day

Shulou Source: shulou.com Published: 2022-06-03 07:37:46 09月14日 Update

This article mainly introduces "how to understand the problem of 12-hour system and 24-hour system to obtain the zero of the day". In daily operation, I believe many people have doubts about how to understand the problem of 12-hour system and 24-hour system to obtain the zero of the day. The editor consulted all kinds of materials and sorted out a simple and useful method of operation. I hope it will be helpful for you to answer the question of "how to understand the 12-hour system and 24-hour system to get the zero of the day"! Next, please follow the editor to study!

The copy code is 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"))

Locally, there is no problem with testing and QA environment testing, but there is a problem with this timing service after going to the public network server. After writing down the log, it is found that the zero point of the day is obtained, and the time obtained after putting it together is the zero point of the previous day. The original server time is 12 hours, and the local environment is 24 hours.

Continuing to dig deeper, it was found that the period from 00:00:00 to 00:59:59 of each day was the date of the day in the 24-hour system, but in the 12-hour system, it was from 12:00:00 to 12:59:59 of the day before yesterday. For example, according to the 24-hour time, today's "2013-09-26 00:00:00", in the 12-hour server, the acquisition is "2013-09-25 12:00:00", the date obtained by DateTime.Now.ToString ("yyyy-MM-dd") is "2013-09-25", then the dt acquisition is "2013-09-25 12:00:00".

It turns out that depending on the hourly system of getting time in C#, you can get it like this

The copy code is 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")

/ / it is determined by the case of H.

Regardless of whether the server's time system is 12 hours or 24 hours, uppercase H gets 24 hours, and lowercase h gets 12 hours.

At this point, the study on "how to understand the 12-hour system and the 24-hour system to get the zero of the day" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Hours time problems that is services code servers learning dates methods more environment help testing different practical next examples uppercase size Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS MySQL Xiaomi Apple