1.时间格式的字符串转date
<pre>
NSString *birthdayStr=@"1986-03-28 00:00:00.000";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];//解决8小时时间差问题
5 NSDate *birthdayDate = [dateFormatter dateFromString:birthdayStr];
</pre>
2.date转字符串
<pre>
NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *strDate = [dateFormatter stringFromDate:date];
</pre>
网友评论