如何获取带前导零的日、分、秒?
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);
将输出:日期:04-15-2013-12-04-51
关于objective-c - 带前导零的 NSDateFormater,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16012233/