标签:
NSString *dateString=@"2015-08-25 14:00:25"; NSDateFormatter *formater=[[NSDateFormatter alloc]init]; formater.dateFormat=@"yyyy-MM-dd HH:mm:ss"; NSDate *date=[formater dateFromString:dateString]; NSCalendar *calendar=[NSCalendar currentCalendar]; NSDateComponents *components=[calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond fromDate:date]; NSLog(@"%d %d %d",components.year,components.month,components.day); NSLog(@"date==%@",date); formater.dateFormat=@"EEE MMM dd HH:mm:ss Z yyyy"; NSString *timeString=[formater stringFromDate:date]; NSLog(@"time string ==%@",timeString); /*输出结果 2015-08-28 14:53:03.518 iOS_basic[1643:49098] 2015 8 25 2015-08-28 14:53:03.518 iOS_basic[1643:49098] date==2015-08-25 06:00:25 +0000 2015-08-28 14:53:03.519 iOS_basic[1643:49098] time string ==Tue Aug 25 14:00:25 +0800 2015 */
标签:
原文地址:http://my.oschina.net/u/2360054/blog/498676