NSDate 当前时间
我需要来自两个 NSDate 等的结果:
第一个 NSDate 例如: 2011-02-20 00:00 AM 每个 iPhone 时区都有
秒。 NSDate 例如:2011-03-20 23:59 PM 每个 iPhone 时区都有什么
我真的很困惑该工具! 我做了如下:
NSCalendar *gCal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *gComponents = [[NSDateComponents alloc] init];
gComponents.day = gDayEventChecker;
gComponents.month = gMonthEventChecker;
gComponents.year = gYearEventChecker;
gComponents.hour = 0;
NSDate *first = [gCal dateFromComponents:gComponents];
NSCalendar *gCal2 = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *gComponents2 = [[NSDateComponents alloc] init];
gComponents2.day = gDayEventChecker2;
gComponents2.month = gMonthEventChecker2;
gComponents2.year = gYearEventChecker2;
gComponents2.hour = 23;
gComponents2.mintue = 59;
NSDate *sec = [gCal2 dateFromComponents:gComponents2];
结果不正确!
第一:2011-02-20 01:30:00 +0000 第二次:2011-03-20 01:30:00 +0000
I need this result from two NSDate or etc:
First NSDate for example: 2011-02-20 00:00 AM What every the iPhone timeZone has
Sec. NSDate for example: 2011-03-20 23:59 PM What every the iPhone timeZone has
I really confuse with the implement!
I done as following:
NSCalendar *gCal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *gComponents = [[NSDateComponents alloc] init];
gComponents.day = gDayEventChecker;
gComponents.month = gMonthEventChecker;
gComponents.year = gYearEventChecker;
gComponents.hour = 0;
NSDate *first = [gCal dateFromComponents:gComponents];
NSCalendar *gCal2 = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *gComponents2 = [[NSDateComponents alloc] init];
gComponents2.day = gDayEventChecker2;
gComponents2.month = gMonthEventChecker2;
gComponents2.year = gYearEventChecker2;
gComponents2.hour = 23;
gComponents2.mintue = 59;
NSDate *sec = [gCal2 dateFromComponents:gComponents2];
The result is not correct!
First: 2011-02-20 01:30:00 +0000
Second: 2011-03-20 01:30:00 +0000
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定您到底想要做什么,但请查看此处的方法
timeIntervalSinceDate
:NSDateNot sure exactly what you're trying to do, but have a look at the method
timeIntervalSinceDate
here : NSDate