Setting NSDate in a “TimePicker” with 24 - 12 hours format xcode

后端 未结 1 971
说谎
说谎 2021-01-07 09:42

I\'m working with some NSDate objects, and well, I use my iPhone with 24 hrs format, so when I was testing my app, everything went fine, but, one of my friends tried the app

1条回答
  •  囚心锁ツ
    2021-01-07 10:36

    Take a look at this like: Find if user prefers 12 / 24 Hour Clock?… think the second answer might be the best for you. Then depending on if the user's device uses a 12 hour clock or 24 hour clock you can set your [currentDate setDateFormat:....] accordingly.

    If you want a 12 hour clock then set currentDate as follows:

    [currentDate setDateFormat:@"yyyy-MM-dd h:mm:ss a"];
    

    If you want a 24 hour clock then set currentDate as follows:

    [currentDate setDateFormat:@"yyyy-MM-dd HH:mm"];
    

    0 讨论(0)
提交回复
热议问题