[英]Unable to get Hijri date from the UIDatePicker in ios Objective C?
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. 我无法在目标c中获得Hijri日期格式,我使用了UIDatePicker,在上面添加了以下代码以将日期显示为hijri。
self.datepicker.datePickerMode = UIDatePickerModeDate;
self.datepicker.calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierIslamic];
I am getting picker as below 我得到如下的选择器
But when i get the date from the UIdatePikcer i get date as 08/03/2017 but not as hijri date. 但是当我从UIdatePikcer获得日期时,我得到的日期为08/03/2017但没有为回历日期。
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. NSDate
对象是一个保存日期但不知道如何显示日期的对象,该日期将呈现给用户。 See it an universal way to store dates, it does not use AM/PM, 24 hours or Gregorian calendar. 看到它是一种通用的日期存储方式,它不使用AM / PM,24小时或公历。
When you print/log a NSDate
object it will use the systems calendar to represent the date. 当您打印/记录NSDate
对象时,它将使用系统日历表示日期。
To format a NSDate
you use NSDateFormatter
which will transform the date to something a user will understand. 要格式化NSDate
请使用NSDateFormatter
,它将日期转换为用户可以理解的日期。 But you will have to tell the NSDateFormatter
how to format the date. 但是您必须告诉NSDateFormatter
如何格式化日期。
The part you forgot is to tell NSDateFormatter
to use the NSCalendarIdentifierIslamic
calendar. 您忘记的部分是告诉NSDateFormatter
使用NSCalendarIdentifierIslamic
日历。
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) 这date is 10/06/1438
今天的日期(2017年3月8日), date is 10/06/1438
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.