如何获得前导零的日、分和秒?
NSDateFormatter *lDateFormatter = [[NSDateFormatter alloc] init];
[lDateFormatter setDateFormat:@"LL-d-yyyy-H-m-s"];
NSString *lTime = [lDateFormatter stringFromDate:[NSDate date]];
// Output : 04-3-2013-14-4-1
如何获得前导零的日、分和秒?
NSDateFormatter *lDateFormatter = [[NSDateFormatter alloc] init];
[lDateFormatter setDateFormat:@"LL-d-yyyy-H-m-s"];
NSString *lTime = [lDateFormatter stringFromDate:[NSDate date]];
// Output : 04-3-2013-14-4-1
您添加了两次日期说明符:LL-dd-yyyy-HH-mm-ss
NSDateFormatter *lDateFormatter = [[NSDateFormatter alloc] init];
[lDateFormatter setDateFormat:@"LL-dd-yyyy-HH-mm-ss"];
NSString *lTime = [lDateFormatter stringFromDate:[NSDate date]];
NSLog(@"Date: %@", lTime);
将输出:Date: 04-15-2013-12-04-51
使用MM-dd-yyyy-HH-mm-ss
格式