iOS NSDateFormatter的dateStyle与timeStyle

充普松
2023-12-01

NSDate *date = [NSDate date];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];


formatter.dateStyle = NSDateFormatterNoStyle;

NSLog(@"date1:%@",[formatter stringFromDate:date]);

//date1:


formatter.dateStyle = NSDateFormatterShortStyle;

NSLog(@"date2:%@",[formatter stringFromDate:date]);

//date2:17/11/24


formatter.dateStyle = NSDateFormatterMediumStyle;

NSLog(@"date3:%@",[formatter stringFromDate:date]);

//date3:2017年11月24日


formatter.dateStyle = NSDateFormatterLongStyle;

NSLog(@"date4:%@",[formatter stringFromDate:date]);

//date4:2017年11月24日


formatter.dateStyle = NSDateFormatterFullStyle;

NSLog(@"date5:%@",[formatter stringFromDate:date]);

//2017年11月24日 星期五



formatter.timeStyle = NSDateFormatterNoStyle;

NSLog(@"time1:%@",[formatter stringFromDate:date]);

//time1:


formatter.timeStyle = NSDateFormatterShortStyle;

NSLog(@"time2:%@",[formatter stringFromDate:date]);

//time2:11:15


formatter.timeStyle = NSDateFormatterMediumStyle;

NSLog(@"time3:%@",[formatter stringFromDate:date]);

//time3:11:15:29


formatter.timeStyle = NSDateFormatterLongStyle;

NSLog(@"time4:%@",[formatter stringFromDate:date]);

//time4:GMT+811:15:29


formatter.timeStyle = NSDateFormatterFullStyle;

NSLog(@"time5:%@",[formatter stringFromDate:date]);

//time5:中国标准时间11:15:29


 类似资料: