【问题标题】:what im doing wrong whit this NSDate - Setting up NSDate我在这个 NSDate 上做错了什么 - 设置 NSDate
【发布时间】:2014-02-21 15:22:33
【问题描述】:

我的托盘创建了一个午餐通知,我得到了当前时间

NSDate *now = [NSDate date];

但我需要将它与另一天的设置进行比较,例如上午 06:55,

我正在尝试使用这个

[NSDateComponets] 

int hour=20;  int minute=40; int second=00;

NSDateFormatter *tempFormatter = [[NSDateFormatter alloc]init];
[tempFormatter setDateFormat:@"hh:mm:ss"];

NSString *message = [NSString stringWithFormat:@" %02d:%02d:%02d",hour, minute, second];
NSDate *day3 = [tempFormatter dateFromString:message];

这说我 (null)

任何帮助将不胜感激。

【问题讨论】:

  • 一个小时 > 12 你需要使用 HH,而不是 hh。

标签: ios date nsdate nsdateformatter nsdatecomponents


【解决方案1】:

您必须在 DateFormat 中使用 HH 而不是 hh

HH 代表 24 小时 格式。 hh 代表 12 小时 格式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    相关资源
    最近更新 更多