2014-06-11 54 views
2

如何在Xcode中將波斯語日期轉換爲格里高利日期?如何將波斯語日期轉換爲xcode中的格里曆日期?

請注意,我想將我的波斯日期並獲得ULAlert鑑於陽曆日期的結果不是的NSLog PLZ告訴我怎麼

+2

請查看文檔:https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DatesAndTimes/Articles/dtCalendars.html –

回答

11

這是你想要的嗎?

NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
df.calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSPersianCalendar]; 
df.dateStyle = NSDateFormatterMediumStyle; 
df.dateFormat = @"yyyy/MM/dd"; 
NSString *stringDate = @"1391/04/07"; 

NSDate *date = [df dateFromString:stringDate]; 

NSLog(@"Date %@", date); 

df.calendar = [NSCalendar currentCalendar]; // or this one if ur current calendar is not GregorianCalendar [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] 
NSString *stringDateConverted = [df stringFromDate:date]; 
[[[UIAlertView alloc] initWithTitle:nil message:stringDateConverted delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] show]; 
+0

PLZ告訴我應該怎麼顯示,警報查看模式不在NSLog – user3716431

+0

編輯答案以顯示日期爲字符串 – LongNV

相關問題