NSDateFormatter设定日期格式
?部分日期格式的總結(jié):
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??????????? 1996.07.10 AD at 15:08:56 PDT
EEE, MMM d, "yy???????????????????????????????????????? Wed,july 10, '99
h:mm a???????????????????????????????????????????????????? 12:08 PM
hh 'o"clock' a,zzzz????????????????????????????????????? 12 o'clock PM, Pacific Daylight Time
K:mm a, z???????????????????????????????????????????????? 0:00 PM, PST
yyyyy,MMMM.dd GGG hh:mm aaa??????????? ????01996.july.10 AD 12:08 PM
?
下面是得到當(dāng)前的年,月,日,時,分,秒:
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];
轉(zhuǎn)載于:https://www.cnblogs.com/wengzilin/archive/2012/03/16/2400666.html
總結(jié)
以上是生活随笔為你收集整理的NSDateFormatter设定日期格式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《应用商务统计分析》前言
- 下一篇: 如何获取JavaCard剩余空间