How can I output the current date and time with the defaulttimezone? When I use following code I always get the time in GMT. Is it possible to convert NSDate to the defaulttimezone? I can’t use the NSDateFormatter because I need an NSDate Object with the correct time.
NSDate *date = [NSDate date];
NSLog(@"Time: %@", date);
Output: 2010-09-26 12:07:12 TimeTest[2641:207] Time: 2010-09-26 12:07:12 GMT
Update: When I have to return an NSDate object with the right time, how can I use NSDateFormatter with setTimeZone?
NSDate* date = [NSDate date];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSTimeZone *tz = [NSTimeZone timeZoneWithName:@"MESZ"];
[formatter setTimeZone:tz];
NSString *datestr = [formatter stringFromDate:date];
NSLog(@"%@", datestr);
NSDate *datenew = [formatter dateFromString:str];
NSLog(@"%@", datenew);
The first NSLog outputs the correct time but when I want to make an NSDate object with the correct time I get the wrong time again.