Hours in NSDate every time in 24-hour style?

前端 未结 5 1638
小鲜肉
小鲜肉 2021-02-05 16:56

I have this date formatter:

 NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
 [timeFormatter setDateFormat:@\"HH:mm\"];

If I u

5条回答
  •  -上瘾入骨i
    2021-02-05 17:20

    From Apple Documentation, the time formatting strings follow Unicode Technical Standard #35.

    As stated in UTR #35, uppercase HH gives you 24-hour style time while lowercase hh gives you 12-hour style time.

    In short, if you need 24-hour style, use [timeFormatter setDateFormat:@"HH:mm"]; and if you need 12-hour style, use [timeFormatter setDateFormat:@"hh:mm"];

提交回复
热议问题