1

uidate picker has proper user zone set.

NSDate *date= Uidatepicker.date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateStyle:NSDateFormatterMediumStyle]; 
[dateFormatter setTimeZone:[NSTimeZone localTimezone]];
//show correct date and time
NSString *string=[dateFormatter stringFromDate:date]; 

//back to date 
NSDate *outDate=[dateFormatter dateFromString:string];

The outdate is passed to another controller and eventually used to query db using time since 1970. The date used in the query has +4 hours (GMT time). I think it should have localtime. I know the NSdate has no timezone but I need the correct time for the db query. The db seems to have correct time since 1970 (based on local time). I am converting to string to check in this case as time is off by +4 hours. Any suggestions and appreciate your help.

4

0 回答 0