开发者

NSDate returns UnDesired Date formate while Converting string From date [duplicate]

开发者 https://www.devze.com 2023-04-12 18:57 出处:网络
This question already has answers here: NSDate format issue (2 answers) Closed 9 years ago. I am trying to convert NSString from NSdate, in that when I try to covert string 2011-10-10 to开发
This question already has answers here: NSDate format issue (2 answers) Closed 9 years ago.

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.

0

精彩评论

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

关注公众号