【问题标题】:Localize NSDate to GMT+1 resulting in new NSDate?将 NSDate 本地化为 GMT+1 导致新的 NSDate?
【发布时间】:2011-07-31 22:10:13
【问题描述】:

我从 CLLocation 经理那里收到了一个时间戳,我想将其更正为英国夏令时 (GMT+1)。我可以使用 dateFormatter 执行此操作并获取 NSString ...

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
NSString *dateString = [dateFormatter stringFromDate:dateNow];
NSLog(@"DATE: %@", dateString);

我的问题是,有没有办法获取 NSDate,将其本地化为 GMT+1,结果是一个新的 NSDate。我想我可以使用上面的方法并添加 dateFromString: 但这感觉就像是一种非常冗长的方式来做我需要的事情。基本上有没有办法去 NSDate > NSDate 而不必跳过中间的 NSString?

【问题讨论】:

    标签: iphone objective-c cocoa-touch


    【解决方案1】:

    请参阅 herehere

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      • 2014-04-22
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      相关资源
      最近更新 更多