How to override TimePattern for 12 hours?

How to override ShortTimePatternand LongTimePatternto always be in 12-hour mode?

The following code only works well 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
source share
2 answers

I believe that “HH” means 24-hour time, and “hh” means 12-hour time.

Try the following:

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

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

+3
source

, , - , - ?

, , , 12- . , .Net- .

- , , ?

+2

Source: https://habr.com/ru/post/1761591/


All Articles