I am not able to get the Hijri date format in objective cI have used a UIDatePicker on which i have added below code for showing the date as hijri.
self.datepicker.datePickerMode = UIDatePickerModeDate;
self.datepicker.calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierIslamic];
But when i get the date from the UIdatePikcer i get date as 08/03/2017 but not as hijri date.
I am using below code to convert date into string.
-(NSString *)convertStringFromDate:(NSDate *)date
{
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"dd/MM/yyyy"];
NSLog(@"date is %@",date);
NSString *dateString = [dateFormatter stringFromDate:date];
return dateString;
}
Please tell me how i can solve this issue ?
A NSDate
object is a object that holds a date but does not know how to present it will be presented to a user. See it an universal way to store dates, it does not use AM/PM, 24 hours or Gregorian calendar.
When you print/log a NSDate
object it will use the systems calendar to represent the date.
To format a NSDate
you use NSDateFormatter
which will transform the date to something a user will understand. But you will have to tell the NSDateFormatter
how to format the date.
The part you forgot is to tell NSDateFormatter
to use the NSCalendarIdentifierIslamic
calendar.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ;
dateFormatter.calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierIslamic];
[dateFormatter setDateFormat:@"dd/MM/yyyy"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"date is %@",dateString);
This gave me date is 10/06/1438
for today's date ( 8 March 2017)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.