views:

40

answers:

2

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"
+3  A: 

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"

Jamie
+2  A: 

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?

Paweł Dyda
+1. I agree. For people who don't use 12 hour clock frequently and do not speak English, AM/PM may be very confusing.
MainMa