Reputation: 11965
When I want a date in 24 hour format, I see the hours such as 05:00. How can I delete the first 0 to get 5:00? I tried this:
NSDateFormatter *fhours = [[NSDateFormatter alloc] init];
[fhours setTimeStyle:NSDateFormatterShortStyle];
mystring = [fhours stringFromDate:newDate];
[fhours release];
Upvotes: 1
Views: 876
Reputation: 740
You should get the right result with the following:
NSDateFormatter *fhours = [[NSDateFormatter alloc] init];
[fhours setDateFormat:@"H:mm"];
mystring = [fhours stringFromDate:newDate];
[fhours release];
Upvotes: 1
Reputation: 1437
Like this
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"HH:mm"];
NSDate *now = [NSDate date];
NSString *theTime = [timeFormat stringFromDate:now];
At line
[timeFormat setDateFormat:@"HH:mm"];
You can erase one H like this
[timeFormat setDateFormat:@"H:mm"];
Upvotes: 7