NSDateFormatter 24小时 [英] NSDateFormatter with 24 hour times

查看:106
本文介绍了NSDateFormatter 24小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个倒数计时器,从当前日期/时间到特定的未来日期/时间倒计时。除了一个问题外,它工作得很好。我使用NSDateFormatter和dateFromString输入未来日期。它似乎无法接受超过12的任何时间(小时),虽然表明它不支持24小时制。有没有办法启用24小时时钟支持或解决方法?以下是我的一些代码:

I have a countdown timer which countsdown from the current date/time to a specific future date/time. It is working great except for one problem. I input the future date using NSDateFormatter and dateFromString. It doesn't seem to be able to accept any time (hour) over 12 though indicating it is not support 24 hour clock. Is there a way to enable 24 hour clock support or a workaround? Here is some of my code:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *myDate = [df dateFromString:@"2010-03-14 15:00:00"];

谢谢

推荐答案

NSDateFormatter遵循日期和时间模式的Unicode标准 。 24小时制小时使用'H':

NSDateFormatter follows the Unicode standard for date and time patterns. Use 'H' for the hour on a 24-hour clock:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *myDate = [df dateFromString:@"2010-03-14 15:00:00"];

这篇关于NSDateFormatter 24小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆