开发者

NSDateFormatter gives different output/wrong (GMT?) time

开发者 https://www.devze.com 2023-04-05 09:18 出处:网络
I have tried setting the timezone and locale of the NSDateFormatter but I can\'t seem to get anything to work. Here is the code

I have tried setting the timezone and locale of the NSDateFormatter but I can't seem to get anything to work. Here is the code

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
NSString *myFireDateString=[@"9/17/11" stringByAppendingString:@" 09:00:00"];
NSDate *myFireDate = [dateFormat dateFromString:myFireDateString];  
NSLog(@"The datestring is is %@",myFireDateString);
NSLog(@"The formatted date is %@",myFireDate);

Here is the output:

The datestring is is 9/17/11 09:00:00

The formatted date is 2011-09-17 开发者_JAVA技巧13:00:00


You need to set a timezone to your dateFormatter:

[dateFormatter setTimeZone:[NSTimeZone defaultTimeZone];

See NSDate from NSString , shows the previous day

0

精彩评论

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