将日期从[NSDate日期]缩短几个小时我在用NSDate *date = [NSDate date];为了得到日期,但我得到的日期是两个小时。
3 回答
![?](http://img1.sycdn.imooc.com/54585094000184e602200220-100-100.jpg)
墨色风雨
TA贡献1853条经验 获得超6个赞
NSDate
description
NSLog()
NSDateFormatter
![?](http://img1.sycdn.imooc.com/5458506b0001de5502200220-100-100.jpg)
拉莫斯之舞
TA贡献1820条经验 获得超10个赞
NSDate * dateGMT = [NSDate date];NSTimeInterval secondsFromGMT = [[NSTimeZone localTimeZone] secondsFromGMT]; NSDate * correctDate = [dateGMT dateByAddingTimeInterval:secondsFromGMT];
![?](http://img1.sycdn.imooc.com/54dc06a60001ef0401000100-100-100.jpg)
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
-(NSDate *)getDateInCurrentSystemTimeZone{ NSDate* sourceDate = [NSDate date]; NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone]; NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate]; NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate]; NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset; NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate]; return destinationDate;}
- 3 回答
- 0 关注
- 461 浏览
添加回答
举报
0/150
提交
取消