开发者

NSDate from NSString , shows the previous day

开发者 https://www.devze.com 2023-04-12 03:08 出处:网络
I have s imple NSDate from NSString as below 开发者_StackOverflow中文版NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

I have s imple NSDate from NSString as below

开发者_StackOverflow中文版
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
                    issueDatabase.album_date = [dateFormatter dateFromString:albumXML.album_date];

but for some reason I'm getting the previous day instead of the current for eample if my

albumXML.album_date is equal 2011-09-01 I'm getting the following stored in my database 2011-08-31


You need to set a timezone to your dateFormatter:

[dateFormatter setTimeZone:[NSTimeZone defaultTimeZone]];

If you don't, you're probably getting the GMT timezone, which could appear in the past depending on where you are on the planet...

0

精彩评论

暂无评论...
验证码 换一张
取 消