简体   繁体   中英

Retrieving NSDate from NSString

I have an iPhone app. that is receiving data with IRFC 3339 timestamp format (eg @"2010-01-29T11:30:00.000+01:00"), as in GData. I want to convert the data to an NSDate

NSDateFormatter *inputFormatter = [[[NSDateFormatter alloc] init] autorelease];
[inputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
[currentEntry setStartTime:[inputFormatter dateFromString: ][currentEntry startTimeString]]];

But I'm missing out how to convert the last part of the string @"2010-01-29T11:30:00.000+01:00": the time offset. Anyone knows what I have to add to this String to take the time offset in account too?

我相信格式字符串中的“ Z”指定了时区偏移量

如果您在使用GData做很多事情,我也建议使用Google的Objective-C客户端代码 ,他们提供了一些类,以帮助从GData创建标准的Objective-C对象。

You will need to strip out the colon and add "ZZZ" to the format string. This parses time zone offsets like "+100" or "-500".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM