- (void)getCurrentDate {
// 获得时间对象
// NSDate *date = [NSDate date];
// // 获得系统的时区
// NSTimeZone *zone = [NSTimeZone systemTimeZone];
// // 以秒为单位返回当前时间与系统格林尼治时间的差
// NSTimeInterval time = [zone secondsFromGMTForDate:date];
// // 然后把差的时间加上,就是当前系统准确的时间
// NSDate *nowDate = [date dateByAddingTimeInterval:time];
// NSLog(@"now date is: %@", nowDate);
// 获取当前时间
NSDate *now = [NSDate date];
// NSLog(@"now date is: %@", now);
NSCalendar *calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitWeekday;
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
NSLog(@"dateComponent is :%@", dateComponent);
NSInteger year = [dateComponent year];
NSInteger month = [dateComponent month];
NSInteger day = [dateComponent day];
NSInteger hour = [dateComponent hour];
NSInteger minute = [dateComponent minute];
NSInteger second = [dateComponent second];
NSInteger weekday = [dateComponent weekday];
NSLog(@"year is: %ld", (long)year);
NSLog(@"month is: %ld", (long)month);
NSLog(@"day is: %ld", (long)day);
NSLog(@"hour is: %ld", (long)hour);
NSLog(@"minute is: %ld", (long)minute);
NSLog(@"second is: %ld", (long)second);
NSLog(@"weekday is: %ld", (long)weekday);
}
获取当前时间、年份、月份、日期等
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 获取当前月份有多少天 numberOfDaysInMonth 即为当月的天数。更多用法查看NSCalendar, ...
- 本文是Netty文集中“Netty 源码解析”系列的文章。主要对Netty的重要流程以及类进行源码解析,以使得我们...