如何在Xcode中将波斯日期转换为格里高利日期?
请注意,我想转换我的波斯日期并在ULAlert视图中获取格里高利日期结果而不是在NSLog中PLZ告诉我如何
答案 0 :(得分: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];