获取当前时间

一  12进制

NSDateFormatter *dateform = [[NSDateFormatter alloc]init];

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];

[dateform setLocale:locale];

dateform.dateFormat = @"hhmmss";

NSString *dateStr = [dateform stringFromDate:[NSDate date]];

二  24进制

NSDateFormatter *dateform = [[NSDateFormatter alloc]init];

dateform.dateFormat = @"hhmmss";

NSString *dateStr = [dateform stringFromDate:[NSDate date]];

三  年月日 星期

- (NSString *)getYears{

NSArray * arrWeek=[NSArray arrayWithObjects:@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六", nil];

NSDate *date = [NSDate date];

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:

NSCalendarIdentifierGregorian];

NSDateComponents *comps = [[NSDateComponents alloc] init];

NSInteger unitFlags = NSCalendarUnitYear |

NSCalendarUnitMonth |

NSCalendarUnitDay |

NSCalendarUnitWeekday |

NSCalendarUnitHour |

NSCalendarUnitMinute |

NSCalendarUnitSecond;

comps = [calendar components:unitFlags fromDate:date];

NSInteger week = [comps weekday];

NSInteger year=[comps year];

NSInteger month = [comps month];

NSInteger day = [comps day];

NSString *dateStr=[NSString stringWithFormat:@"%ld年%ld月%ld日  %@",year,month,day,[arrWeek objectAtIndex:week-1]];

return dateStr;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容