我試圖用時間將NSString
轉換爲NSDate
。這是我現在正在做的:如何將NSString隨時間轉換爲NSDate?
NSString *myDateIs= @"2012-07-14 11:30:40 AM ";
NSDateFormatter* startTimeFormat = [[NSDateFormatter alloc] init];
[startTimeFormat setDateFormat:@"YYYY-MM-dd hh:mm:ss a "];
NSDate*newStartTime = [startTimeFormat dateFromString:myDateIs];
輸出是2012-07-14 06:00:40 +0000
。日期是正確的,但時間不正確。 我如何獲得正確的時間? 謝謝。
使用此 NSString * myDateIs = @「2012-07-14 11:30:40 AM」; NSDateFormatter * startTimeFormat = [[NSDateFormatter alloc] init]; [startTimeFormat setDateFormat:@「YYYY-MM-dd hh:mm:ss a」]; [startTimeFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@「GMT」]]; NSDate * newStartTime = [startTimeFormat dateFromString:myDateIs]; – 2012-07-16 08:01:47
謝謝..現在它的工作正常... :) – Mani 2012-07-16 08:17:46