iphone – 将NSDate设置为特定的日期,时间和时区

栏目: IOS · 发布时间: 7年前

内容简介:我想知道是否可以在NSCateendar对象上设置时区,用于从NSDateComponents创建NSDate.我没有尝试过这个,不知道是否可以工作,但这可能值得一试.http://stackoverflow.com/questions/3655616/setting-an-nsdate-to-specific-date-time-and-timezone

我需要将NSDate设置为iPhone App的特定日期,时间和时区.

下面的示例代码在iOS 4上可以正常工作,因为setTimeZone与iOS 4一起引入.如何在不使用setTimeZone的情况下轻松将NSDate设置为日期,时间和时区,以便它可以在iOS 3.0设备上使用?

NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:2010];
[comps setMonth:8];
[comps setDay:24];
[comps setHour:17];
[comps setMinute:5];
[comps setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"] ];

NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *referenceTime = [cal dateFromComponents:comps];

猜猜这应该很简单,但不知何故NSDate,组件和日历和我不是好朋友…

我想知道是否可以在NSCateendar对象上设置时区,用于从NSDateComponents创建NSDate.我没有尝试过这个,不知道是否可以工作,但这可能值得一试.

http://stackoverflow.com/questions/3655616/setting-an-nsdate-to-specific-date-time-and-timezone


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Getting Real

Getting Real

Jason Fried、Heinemeier David Hansson、Matthew Linderman / 37signals / 2009-11-18 / USD 24.99

Getting Real details the business, design, programming, and marketing principles of 37signals. The book is packed with keep-it-simple insights, contrarian points of view, and unconventional approaches......一起来看看 《Getting Real》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具