【问题标题】:dateWithTimeIntervalSinceNow giving silly answersdateWithTimeIntervalSinceNow 给出愚蠢的答案
【发布时间】:2011-01-23 18:39:24
【问题描述】:

这就是我得到的代码:

NSDate *myCustomDate = [NSDate dateWithTimeIntervalSinceNow:10];
NSLog(@"My custom date: %@", myCustomDate);

它返回:My custom date: 0023-01-23 18:37:17 +0000

为什么它给出的是 2011 年而不是 2011 年的愚蠢答案?其他一切都是正确的。

【问题讨论】:

  • 我刚刚尝试了代码,它似乎工作正常:我的自定义日期:2011-01-23 19:45:19 +0100。时区设置可能有问题?
  • [NSDate date] 打印什么?
  • 现在完美运行。问题是由于某种原因我的日历设置为日语。
  • 您能否将fluchtpunkts 的答案标记为已接受?让人们一眼就能看出你的问题已经解决了吗?

标签: iphone objective-c cocoa-touch nsdate


【解决方案1】:

您的设备正在使用日本日历。

转到设置/国际/日历并改回公历。

【讨论】:

    【解决方案2】:

    嗯,有趣.. 我完全复制了该代码并得到了My custom date: 2011-01-23 18:44:14 +0000,这看起来是正确的。也许您的日历已关闭?这样做会得到什么?

    NSDate *myDate = [NSDate date];
    NSLog(@"My date: %@", myDate);
    NSDate *myCustomDate = [NSDate dateWithTimeIntervalSinceNow:10]; 
    NSLog(@"My custom date: %@", myCustomDate);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 2011-08-24
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      相关资源
      最近更新 更多