【问题标题】:Objective C - NSDateFormatter returns nil?Objective C - NSDateFormatter 返回 nil?
【发布时间】:2010-10-26 18:24:15
【问题描述】:
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.sss"];
self.date = [dateFormatter dateFromString:dateString];

代码可以很好地处理这个字符串

  • “2007-06-10 06:31:54.935”

但不适用于这个(如果时间设置为 0,则返回 nil):

  • “2007-06-10 00:00:00.000”

【问题讨论】:

    标签: objective-c nsdate nsdateformatter


    【解决方案1】:

    尝试使用@"yyyy-MM-dd HH:mm:ss.SSS"(小写秒的大写S)。
    请参阅Date Format Patterns 指南。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-18
      相关资源
      最近更新 更多