我試圖將NSString
以12小時的格式轉換爲NSDate
。 (在IOS 6)NSDateFormatter格式問題
代碼:
NSString *Bdt = @"05/23/2012 08:00 AM"
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
[df setDateFormat:@"MM/dd/yyyy hh:mm a"];
NSDate *bd = [df dateFromString:Bdt];
NSLog(@"%@",bd);
輸出:
2012-05-23 8時00分○○秒0000應該是2012-05-23 08:00 AM
代碼有什麼問題?
感謝
這裏沒有錯。如果你NSLog一個NSDate(即調用'description'),你將得到'2012-05-23 08:00:00 + 0000'。 – 2013-03-16 07:56:14
你正在上午08:00上午 – 2013-03-16 07:56:34
@MatthiasBauch:是的,但它應該是'2012-05-23 08:00 AM' – user1859900 2013-03-16 07:56:53