标签:style blog io color os sp for on div
iOS 时区:
1 //先是将指定时区的日期转换为当前时区时间: 2 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 3 [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; 4 [formatter setTimeZone:[NSTimeZone defaultTimeZone] ] ; 5 NSDate *time = [formatter dateFromString:@"2011-09-27 10:11:30 +0600"]; 6 NSLog(@"Local time is %@",[formatter stringFromDate: time]);
1 //然后是将当前时区时间转换为特定时区的: 2 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 3 [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; 4 [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Tokyo"]]; 5 NSLog(@"Now Tokyo time is %@",[formatter stringFromDate:[NSDate date]]);
1 //下面是将指定时区的某个日期时间转化为指定时区的时间 2 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 3 [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; 4 [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Tokyo"]]; 5 NSDate *time = [formatter dateFromString:@"2011-09-27 10:11:30 +0600"]; 6 NSLog(@"Tokyo time is %@",[formatter stringFromDate: time]);
标签:style blog io color os sp for on div
原文地址:http://www.cnblogs.com/mo-shou/p/4156625.html