哈哈的笑  

1.时间格式的字符串转date

1 NSString *birthdayStr=@"1986-03-28 00:00:00.000";
2 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
3 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
4  [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];//解决8小时时间差问题
5 NSDate *birthdayDate = [dateFormatter dateFromString:birthdayStr];

2.date转字符串

1 NSDate *date = [NSDate date];
2 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
3 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
4 NSString *strDate = [dateFormatter stringFromDate:date];

 

posted on 2016-09-02 16:53  哈哈的笑  阅读(30116)  评论(0编辑  收藏  举报