首页 > 其他分享 >NSDateFormatter设定日期格式

NSDateFormatter设定日期格式

时间:2023-03-30 20:07:15浏览次数:39  
标签:设定 int dd dateFormatter NSDateFormatter mm hh date 格式


部分日期格式的总结:

NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init]autorelease];

[dateFormatter setAMSymbol:@"AM"];

[dateFormatter setPMSymbol:@"PM"];

[dateFormatter setDateFormat:@"dd/MM/yyyy hh:mmaaa"];

NSDate *date = [NSDate date];

NSString * s = [dateFormatter stringFromDate:date];

显示效果为:10/05/2010 03:49PM


下面附上几个格式:这个是从Cocoachina找来的:

yyyy:MM:dd G 'at' HH:mm:ss zzz           

EEE, MMM d, "yy                                        

h:mm a                                                    

hh 'o"clock' a,zzzz                                     

K:mm a, z                                                

yyyyy,MMMM.dd GGG hh:mm aaa                01996.july.10 AD 12:08 PM


下面是得到当前的年,月,日,时,分,秒

NSCalendar *cal = [NSCalendar currentCalendar];

unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;

NSDateComponents *dd = [cal components:unitFlags fromDate:date];

int y = [dd year];

int m = [dd month];

int d = [dd day];

int h = [dd hour];

int m = [dd minute];

int s = [dd second];





标签:设定,int,dd,dateFormatter,NSDateFormatter,mm,hh,date,格式
From: https://blog.51cto.com/u_548275/6160126

相关文章