2013-11-21 63 views
0

我是新來的Xcode,請參見下面的代碼,並鏈接 enter link description herenslocale問題迄今

{ 
NSString * TempDate = [NSString stringWithFormat:@"%@ %@ %@",Datelbl.text,yearString,TimeLbl.text]; //Thursday, November 21 2013 5:35 PM 

[dateFormatter setLocale:[NSLocale currentLocale]]; 
[dateFormatter setDateFormat :@"EEEE',' MMMM d yyyy hh:mm a"]; 
AppointmentDate = [dateFormatter dateFromString:TempDate]; //NSDate 
Appointment = [dateFormatter stringFromDate:AppointmentDate]; //NSString 
} 

這裏,appointmentDate返回該值 - > 2013年11月21日12:05:00 +0000, 約會返回此值 - > 2013年11月21日星期四下午05:35。

我需要2013-11-21 05.35 PM。那麼,如何管理這個GMT問題。

+0

TempDate是什麼樣子? –

+0

@ramdy:Plz把你之前的問題與這個聯繫起來,那對你有幫助。 –

回答

-1

編輯:

[dateFormatter setDateFormat : @"EEEE, MMMM d yyyy hh:mm a"]; 

String value not converting to date format

+1

您的格式與輸入格式不匹配:'2013年11月21日星期四下午5:35'。此外,問題不是在格式,但與時區 – rckoenes

+0

@suhit,我可以知道,你給我投票問題?? – Ramdhas

0

試試這個:

NSString *date = @"Thursday, November 21 2013 3:05 PM"; 

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat : @"EEEE, MMMM d yyyy hh:mm a"]; 
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; 
NSDate *AppointmentDate = [dateFormatter dateFromString:date]; 

NSLog(@"DATE--> %@",AppointmentDate); 

輸出:

DAT - > 2013年11月21日15:05:00 +0000

注:NSDate的將在24小時格式。你需要將它轉換成字符串是你想要的03:05 ...

+0

但是這樣你創建一個「壞」的NSDate對象。時區應設置爲輸入的時區(或創建字符串時的輸出),以便NSDate本身爲UTC。 –