5
我有这样如何获取小时,日期格式
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"HH:mm:ss"];
从此我只需要HH值的时间格式。
如何获取价值
我有这样如何获取小时,日期格式
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"HH:mm:ss"];
从此我只需要HH值的时间格式。
如何获取价值
NSDateFormatter *timeFormatter = [[[NSDateFormatter alloc]init]autorelease];
timeFormatter.dateFormat = @"HH";
NSString *datestringofHour= [timeFormatter stringFromDate: localDate];
现在datestringofHour
变量,你将有时间值的字符串。
另外一个如下,可以给你小时,分钟,秒的整数值
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
NSInteger hour= [components hour];
NSInteger minute = [components minute];
NSInteger second = [components second];
只需切换:
[df setDateFormat:@"HH:mm:ss"];
到:
[df setDateFormat:@"HH"];
http://stackoverflow.com/questions/10861433/in-objective-c-to-get-the-我们需要使用n访问此 –
哇...... HH:mm:ss'给出'12:45:32',你只需要'HH' ...不要告诉我你已经搜索了超过4秒钟,然后发布这个。 – Cyrille