开发者

How to override TimePattern to be 12 hour time?

开发者 https://www.devze.com 2023-01-13 17:13 出处:网络
How do I override the ShortTimePattern and LongTimePattern to always be in 12 hour time? The following code works well only with en-US, because other cultures have different patterns.

How do I override the ShortTimePattern and LongTimePattern to always be in 12 hour time?

The following code works well only with en-US, because other cultures have different patterns.

开发者_开发知识库    System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongTimePattern = "h:mm:ss tt"
    System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern = "h:mm tt"


I believe 'HH' means 24 hour time, while 'hh' means 12 hour time.

Try this:

System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern = "HH:mm:ss"

System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongTimePattern = "HH:mm:ss"


The first thing that comes to my mind is: why you ever want to that?

Mind that for non-US people 12-hour time could be hard to understand. There are reasons why most of .Net's classes are locale-aware.

If you ever going to sell your app abroad, you might be forced to change it, so what's the point of doing the same thing twice?

0

精彩评论

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