开发者

Problem with DateTime toString()

开发者 https://www.devze.com 2023-03-04 13:37 出处:网络
Hy! The DateTime.toString() gives 12 hours more back as in the debugger written. Do i need CultureInfo?

Hy!

The DateTime.toString() gives 12 hours more back as in the debugger written.

Do i need CultureInfo?

(in austria we are used to count from 0 - 24 for the hours)

thx

My Code:

DateTime dtime = new DateTime(1900, 1, 1, Convert.ToInt32开发者_如何学Go(tim2.hour), Convert.ToInt32(tim2.minute), Convert.ToInt32(tim2.second));
label2.Text = dtime.ToString    ("hh:mm:ss.F");

Debugger:

+       dtime   {01.01.1900 00:05:48}   System.DateTime

+       label2.Text "12:05:48"  string


hh is a 12 hour format (i.e. 0:05 is 12:05 AM). It sounds like you want to use HH instead, which is a 24 hour format:

label2.Text = dtime.ToString ("HH:mm:ss.F");

Relevant documentation for the formatters can be found here.


In custom date format string, hh displays the hour using 12-hour clock. If you want to have 24-hour clock, use HH.


00:05:48 would be 12 Midnight. If you want your time formated with a 24 hour time, then you should use dtime.ToString('HH:mm:ss.F");

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号