标签:
NSDate 和 NSDateFormatter;
--获取当前时间:
NSDate *now = [NSDate date];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSTimeInterval interval = [zone secondsFromGMT];
now = [now dateByAddingTimeInterval: interval];
--将字符串转为日期:
NSDateFormatter *formatter = [NSDateFormatter alloc] init];
[formatter setTimeZone: [NSTimeZone timeZoneWithAbbreviation: @"UTC"]];
NSString *formatStr = @"yyyy-MM-dd HH:mm:ss";
[formatter setDateFormat: formatStr];
NSDate *date = [formatter dateFromString: dateStr];
--将日期转为字符串:
NSDateFormatter *formatter = [NSDateFormatter alloc] init];
[formatter setTimeZone: [NSTimeZone timeZoneWithAbbreviation: @"UTC"]];
NSString *formatStr = @"yyyy-MM-dd HH:mm:ss";
[formatter setDateFormat: formatStr];
NSString *dateStr = [formatter stringFromDate: date];
标签:
原文地址:http://www.cnblogs.com/jxcl/p/4828561.html