当我将时间戳格式化为 NSDate 字符串时,如何摆脱小时显示的额外 0?
How do I get rid of the extra 0 being displayed on hours when i format timestamp to NSDate string?
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateFormat:@"hh:mm a"];
NSString *strDate = [dateFormatter stringFromDate:taskStartDate];
现在它的输出时间像:01:00PM 而不是 1:00PM
如果您不想要两位数的小时,请不要使用 hh
进行格式化。使用 h
.
[dateFormatter setDateFormat:@"h:mm a"];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateFormat:@"hh:mm a"];
NSString *strDate = [dateFormatter stringFromDate:taskStartDate];
现在它的输出时间像:01:00PM 而不是 1:00PM
如果您不想要两位数的小时,请不要使用 hh
进行格式化。使用 h
.
[dateFormatter setDateFormat:@"h:mm a"];