当我想要 24 小时格式的日期时,我会看到诸如 05:00 之类的时间。如何删除第一个 0 以获得 5:00?我试过这个:
NSDateFormatter *fhours = [[NSDateFormatter alloc] init];
[fhours setTimeStyle:NSDateFormatterShortStyle];
mystring = [fhours stringFromDate:newDate];
[fhours release];
当我想要 24 小时格式的日期时,我会看到诸如 05:00 之类的时间。如何删除第一个 0 以获得 5:00?我试过这个:
NSDateFormatter *fhours = [[NSDateFormatter alloc] init];
[fhours setTimeStyle:NSDateFormatterShortStyle];
mystring = [fhours stringFromDate:newDate];
[fhours release];
像这样
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"HH:mm"];
NSDate *now = [NSDate date];
NSString *theTime = [timeFormat stringFromDate:now];
在线
[timeFormat setDateFormat:@"HH:mm"];
你可以像这样擦除一个H
[timeFormat setDateFormat:@"H:mm"];
您应该通过以下方式获得正确的结果:
NSDateFormatter *fhours = [[NSDateFormatter alloc] init];
[fhours setDateFormat:@"H:mm"];
mystring = [fhours stringFromDate:newDate];
[fhours release];