在ios中以特定格式获取伊斯兰日期和格里高利日期

时间:2015-02-24 11:58:01

标签: ios objective-c nsdate nsdateformatter

我希望以2014年2月24日的格式获取当前日期。我想要 也可以采用与5 jumada al-awwal 1436相同的格式获得伊斯兰日期 我怎么能这样做,我看到其他的东西,但最关心整数组件。 我写了这个只获得组件的代码

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
NSInteger day = [components day];
NSInteger month = [components month];
NSInteger year = [components year];

NSLog(@"%@",components);

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE"];
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);

我将此用于伊斯兰日期

NSCalendar *islamicCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar]; 
NSDate *today = [NSDate date]; 
[islamicCalendar rangeOfUnit:NSDayCalendarUnit startDate:&today interval:NULL forDate:today]; 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setCalendar:islamicCalendar];
[dateFormatter setTimeStyle:NSDateFormatterFullStyle];
[dateFormatter setDateStyle:NSDateFormatterFullStyle];
 //english output 
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
NSString * islamicDateString = [dateFormatter stringFromDate:today];
NSLog(@"%@", islamicDateString);

0 个答案:

没有答案