2012-12-07 58 views
1

有誰知道如何將DateTime從英文轉換爲西班牙文?在iPhone中將日期時間從英語轉換爲西班牙語?

E.g轉換:

December 07, 10:42AM 

Diciembre 07, 10:42AM 

請幫助我。如何轉換?

在此先感謝。

我嘗試這樣做:

NSLocale *frLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"es"] autorelease]; 
NSLog(@"%@", [frLocale displayNameForKey:NSLocaleIdentifier value:@"December 07, 10:42AM"]); 
// Value comes Null 

回答

2

嘗試像下面這將有助於

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; 
    [dateFormatter setDateFormat:@"MMMM dd',' hh:mma"]; 
    NSDate *dateTmp = [dateFormatter dateFromString:@"December 07, 10:42AM"]; // getting date from string with english locale 
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"es"]]; 
    [dateFormatter setAMSymbol:@"AM"]; // default AM symbol for spanish is a.m. 
    [dateFormatter setPMSymbol:@"PM"]; // default PM symbol for spanish is p.m. 
    NSString *strDate = [dateFormatter stringFromDate:dateTmp]; // getting string from date with spanish locale 
    NSLog(@"%@",strDate); 
+0

感謝您的幫助 – SampathKumar

+0

我還有一個疑問 – SampathKumar

+0

你有什麼疑問? – Narayana

相關問題