标签:val string bsp format set etl mat oca 间隔
由于苹果商店上线应用24小时内会不稳定,更新提醒可能会陷入死循环,更新提醒需要24小时后弹出,需要把苹果返回的上线时间转换为本地时间故写了下边的方法:
//将UTC日期字符串转为本地时间字符串
//输入的UTC日期格式2013-08-03T04:53:51+0000
-(NSString *)getLocalDateFormateUTCDate:(NSString *)utcDate
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//输入格式
[dateFormatter setDateFormat:@"yyyy-MM-dd‘T‘HH:mm:ssZ"];
NSTimeZone *localTimeZone = [NSTimeZone localTimeZone];
[dateFormatter setTimeZone:localTimeZone];
NSDate *dateFormatted = [dateFormatter dateFromString:utcDate];
//输出格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:dateFormatted];
return dateString;
}
当前时间与dateString的时间间隔
- (NSTimeInterval)currentTimeFromDateString:(NSString *)dateString
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date1 = [formatter dateFromString:dateString];
NSDate *date2 = [NSDate date];
NSTimeInterval aTimer = [date2 timeIntervalSinceDate:date1];
return aTimer;
}
将UTC日期字符串转为本地时间字符串,如@"yyyy-MM-dd'T'HH:mm:ssZ"转换为本地时间
标签:val string bsp format set etl mat oca 间隔
原文地址:http://www.cnblogs.com/chaicla-ios/p/6829188.html