在iphone中以24小时格式检索小时 [英] Retrieving hours in 24 hour format in iphone
本文介绍了在iphone中以24小时格式检索小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这种格式来获取小时
I am using this format to get hours
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"hh";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSString *date = [dateFormatter stringFromDate:now];
NSInteger myHour = [date intValue];
问题是它返回,例如 4Pm
i希望它返回 16
而不是4.我该怎么做?我尝试用单一h替换hh无效。
The problem is it returns e.g 4Pm
i Want it to return 16
Instead of 4. How can I do that? I tried replacing hh by single h by of no avail.
推荐答案
这里您的输入:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh"];
NSDate *Yourcurrenttime = [dateFormatter dateFromString:Yourstring];
并将日期转换为String ..
And date converted to the String ..
[dateFormatter setDateFormat:@"HH"];
NSString *date = [dateFormatter stringFromDate:now];
NSInteger myHour = [date intValue];
这篇关于在iphone中以24小时格式检索小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文