How to convert Persian date to Gregorian date in xcode?

How to convert Persian date to Gregorian date in Xcode?

Please note that I want to convert my Persian date and get the result of the Gregorian date in the ULAlert view not in NSLog plz, show me how

+3
source share
2 answers

Is this what you want?

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]; 
+11
source

Swift 4.2 / xCode 10

I have a simple extension for a Persian date as a collector. he has a converter for gregorian. You may be interested.

https://github.com/Fridday/PersianDatePicker

0
source

All Articles