Reputation: 2318
I have a string:
stringValue = 2013-06-11 06:01:28.
When i try to convert it using NSDateFormatter it becomes like this: date = 2013-06-10 22:01:28 +0000
.
I've read that they are the same point in time. In fact when i get the string value of the date, i get the string above.
If they're the same, is there a way to have a date with value equal to my string above? Can i have an NSDate *date = 2013-06-11 06:01:28? If yes, how can I do that?
Upvotes: 1
Views: 193
Reputation: 670
It happen because when you convert string to date it convert to GMT time format
if you want date same as your string value than you have to set your stadard local time
Like
NSDate *date=[[NSDate alloc]init];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Kolkata"]];
[timeFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss'"];
date = [timeFormat dateFromString:@"2013-06-11 06:01:28"];
hope it may help you
Upvotes: 1
Reputation: 1544
Use this formatter:
NSDateFormatter* f = [[[NSDateFormatter alloc] init] autorelease];
[f setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
Upvotes: 0