[转]根据时间(NSDate)获取具体的信息:月份、星期、天等
生活随笔
收集整理的這篇文章主要介紹了
[转]根据时间(NSDate)获取具体的信息:月份、星期、天等
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
[iPhone類代碼]計算時間,month,week and day,hour , minutes and second
//initializtion parameterNSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now;
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
???????????????????????????????????????? NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
now=[NSDate date];
comps = [calendar components:unitFlags fromDate:now];
week = [comps weekday];????
month = [comps month];
day = [comps day];
hour = [comps hour];
min = [comps minute];
sec = [comps second];
//Week:
1 --星期天
2--星期一
3--星期二
4--星期三
5--星期四
6--星期五
7--星期六
轉載于:https://www.cnblogs.com/sevenology/p/4079892.html
總結
以上是生活随笔為你收集整理的[转]根据时间(NSDate)获取具体的信息:月份、星期、天等的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 磁盘不见了只剩一个c盘_非常的奇葩,终于
- 下一篇: 阿里最新分享Redis全套学习笔记PDF