NSDate returns UnDesired Date formate while Converting string From date [duplicate]
I am trying to convert NSString from NSdate, in that when I try to covert string 2011-10-10
to开发者_StackOverflow社区 nsdate
, it returns 2011-10-09 18:30:00 +0000 as date , I am doing in xcode 3.2.5 and in simulator.
Here is my code
+(NSDate *)ConverStringToDate:(NSString *)str_Date
{
NSDateFormatter * lastFormatter = [[NSDateFormatter alloc]init];
[lastFormatter setDateFormat:@"yyyy-MM-dd"];
[lastFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
lastDate = [lastFormatter dateFromString:@"2011-10-10"];
return lastDate;
}
The Last date is not proper. Please help me from this issue.
Specifying the locale as US, it makes up for the time difference by default. It probably returns a date which is valid in your time zone (the one your device is set up as, where are you?). There's a question about time zones here.
精彩评论