我需要更改我的时间格式和我在Google上搜索的日期这是怎么做的,我发现如何使用该代码更改数据格式:
NSString *hora=@"01:32";
NSDateFormatter *formatHora = [[NSDateFormatter alloc] init];
[formatHora setDateFormat:@"hh:mm"];
NSDate *dateHora = [formatHora dateFromString:hora];
[formatHora setDateFormat:@"HH:mm"];
NSString* horaFormatoCorrecto = [formatHora stringFromDate:dateHora];
但我尝试同样的时间和代码不去,我需要将日期的格式更改为24h,我的代码:
NSString *hora=@"01:32";
NSDateFormatter *formatHora = [[NSDateFormatter alloc] init];
[formatHora setDateFormat:@"hh:mm"];
NSDate *dateHora = [formatHora dateFromString:hora];
[formatHora setDateFormat:@"HH:mm"];
NSString* horaFormatoCorrecto = [formatHora stringFromDate:dateHora];
提前致谢。
答案 0 :(得分:0)
请检查以下代码 -
NSString *hora=@"01:32 PM";
NSDateFormatter *formatHora = [[NSDateFormatter alloc] init];
[formatHora setDateFormat:@"hh:mm a"];
NSDate *dateHora = [formatHora dateFromString:hora];
[formatHora setDateFormat:@"HH:mm"];
NSString* horaFormatoCorrecto = [formatHora stringFromDate:dateHora];