ios 获取日期(年、月、日、星期、时、分、秒)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sisitwo/article/details/49588365
//
+(NSDictionary *)getTimeFromDate:(NSDate *)date
{
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSLocale *zhLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    [calendar setLocale:zhLocale];
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    comps = [calendar components:unitFlags fromDate:date];
    
    NSDictionary *result = @{
                             @"year":[NSNumber numberWithInt:[comps year]],
                             @"month":[NSNumber numberWithInt:[comps month]],
                             @"day":[NSNumber numberWithInt:[comps day]],
                             @"hour":[NSNumber numberWithInt:[comps hour]],
                             @"minute":[NSNumber numberWithInt:[comps minute]],
                             @"second":[NSNumber numberWithInt:[comps second]],
                             @"week":[NSNumber numberWithInt:[comps weekday] - 1]
                             };
    return result;
}

展开阅读全文

没有更多推荐了,返回首页