NSDateComponents中的sethours [英] sethours in NSDateComponents

查看:87
本文介绍了NSDateComponents中的sethours的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在NSDateComponents中搜索,我编写了以下代码

I'm trying to sethours in NSDateComponents, I wrote the following code

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];

[dateComps setDay:intDay];
[dateComps setMonth:intMonth];
[dateComps setYear:intYear];
[dateComps setHour:intHoures];
[dateComps setMinute:intMinutes];

NSDate *itemDate;
itemDate = [calendar dateFromComponents:dateComps];

NSLog(@"reminder date: %@", itemDate);

但是当我将小时数设置为13时,它将其设置为11.我想要24小时的小时数。任何人都可以帮我解决这个问题吗?

but when I set the hours as 13, it sets it as 11. I want hours in 24 style. Anyone can help me in this issue?

先谢谢。

推荐答案

小时的时差表明你可能有时区问题,你可以尝试设置日期的时区,我知道 NSDateFormatter timeZone 属性,我怀疑 NSDateComponents 是否有timeZone属性。但是,您可以为日历设置timeZone

Time difference in the hours indicate that you might have problem with time zone, you could try to set the timezone for the date, I know NSDateFormatter has timeZone Property,I doubt if NSDateComponents have timeZone property. However you could set the timeZone for calendar

[calendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];

这篇关于NSDateComponents中的sethours的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆