0

如何获得前导零的日、分和秒?

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
4

2 回答 2

4

您添加了两次日期说明符: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

于 2013-04-15T09:53:50.290 回答
2

使用MM-dd-yyyy-HH-mm-ss格式

于 2013-04-15T09:54:19.927 回答