Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望在我的应用程序中使用 12 小时时钟格式,以便用户可以将 15:00 写为下午 3:00,因此我不需要创建按钮 am 和 pm。谢谢
可能您想使用 24 小时制格式而不是 12 小时制格式。因此,在格式字符串中使用带有 H 的 NSDateFormatter。使用其中一种预定义格式最终将使用您的系统本地化,这可能是 12 小时格式。
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init]; [inputFormatter setDateFormat:@"HH:mm"];