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?
精彩评论