回历(伊斯兰)日历的问题! [英] hijri (islamic) calendar problem!
问题描述
我阳历日期转换为回历(伊斯兰)的日期。之后可以在网络上搜索,我发现了一个源$ C $ C,将它。
我从转换Java和PHP的code到C碱基。
该实施有时没有任何问题的工作。但有些日子有问题。
我需要你的帮助,无论是修复实施或提供code,将没有任何问题的工作!
顺便说一句,我发现另一个来源$ C $ C( HTTP://emr.cs.iit。埃杜/〜莱因戈尔德/ calendar.C)是C ++的基础。因为我不知道C ++,如果任何人可以转换为C Base或目标C是prefect(还不能确定这个code将正常或不工作)。
P.S。您可以检查正确日期:islamicfinder.org/Hcal/index.php
无效gregorian_to_hijri为(int * h_y,为int * h_m,为int * H_D,诠释g_y,诠释g_m,诠释G_D)
{
INT年,月,日; 诠释ZYR;
INT ZD;
INT ZM;
INT ZY; 浮ZJD;
INT ZL;
INT锌;
INT ZJ; 年= g_y;
月= g_m;
天= G_D;
ZYR =年;
ZD =天;
ZM =月;
ZY = ZYR; 如果((ZY> 1582)||((ZY == 1582)及及(ZM→10))||((ZY == 1582)及及(ZM == 10)及与放大器(ZD> 14)))
{
ZJD =((1461 *(ZY + 4800 +((ZM - 14)/ 12)))/ 4)
+((367 *(ZM - 2 - 12 *(((ZM - 14)/ 12))))/ 12)
- ((3 *(((ZY + 4900 +((ZM - 14)/ 12))/ 100)))/ 4)+ ZD - 32075;
}
其他
{
ZJD = 367 * ZY - ((7 *(ZY + 5001 +((ZM - 9)/ 7)))/ 4)
+((275 * ZM)/ 9)+ ZD + 1729777;
} ZL = ZJD - 1948440 + 10632;
锌=((ZL - 1)/ 10631);
ZL = ZL - 10631 *锌+ 354;
ZJ =(((10985 - ZL)/ 5316))*((INT)((50 * ZL)/ 17719))
+((ZL / 5670))*((INT)((43 * ZL)/ 15238)); ZL = ZL - (((30 - ZJ)/ 15))*(((17719 * ZJ)/ 50))
- ((ZJ / 16))*(((15238 * ZJ)/ 43))+ 29; ZM =((24 * ZL)/ 709);
ZD = ZL - ((709 * ZM)/ 24);
ZY = 30 *锌+ ZJ - 30; * h_y = ZY;
* h_m = ZM;
* H_D = ZD;
}
假设这是一个苹果(可可)或iOS(可可触摸)的应用程序,因为这就是你最常看的目标C,那么你可以做一些事情像这样的:
//创建一个阳历
NSCalendar *的GregorianCalendar = [[NSCalendar页头] initWithCalendarIdentifier:NSGregorianCalendar];//设置一个公历日期的组成部分
NSDateComponents * gregorianComponents = [[NSDateComponents的alloc]初始化];gregorianComponents.day = 4;
gregorianComponents.month = 12;
gregorianComponents.year = 2010;//创建日期
* NSDate的日期= [GregorianCalendar的dateFromComponents:gregorianComponents];[gregorianComponents发布]
[GregorianCalendar的释放];
//然后创建一个伊斯兰历
NSCalendar * hijriCalendar = [[NSCalendar页头] initWithCalendarIdentifier:NSIslamicCivilCalendar];//并抓住这些日期组件的相同日期
NSDateComponents * hijriComponents = [hijriCalendar部分组成:(NSDayCalendarUnit |
NSMonthCalendarUnit |
NSYearCalendarUnit)
寄件者:日期];
的NSLog(@[在回历 - >]天:%ld的月份:%ld的年份:LD%,
[hijriComponents日]
[hijriComponents月]
[hijriComponents年]);[hijriCalendar发布]
如果你想要的是当前日期,则可以跳过完全建立阳历日子,只是这样做:
//创建一个伊斯兰历
NSCalendar * hijriCalendar = [[NSCalendar页头] initWithCalendarIdentifier:NSIslamicCalendar];//并抓住日期组件当前日期
NSDateComponents * hijriComponents = [hijriCalendar部分组成:(NSDayCalendarUnit |
NSMonthCalendarUnit |
NSYearCalendarUnit)
寄件者:[NSDate的日期]];[hijriCalendar发布]
I would convert Gregorian date to Hijri (Islamic) date. After may search on the web, I found a source code to convert it. I converted the code from Java and PHP to C base.
The implement some times working without any problem. But some days has problem.
I need your help either fix the implement or a available code that will work without any problem! BTW I found another source code (http://emr.cs.iit.edu/~reingold/calendar.C) that is C++ base. As I don't know C++ if anyone can convert that to C Base or Objective C would be prefect (still not sure this code will work correctly or not).
P.S. You can check the correct date in: islamicfinder.org/Hcal/index.php
void gregorian_to_hijri(int* h_y, int* h_m, int* h_d, int g_y, int g_m, int g_d)
{
int year, month, day;
int zyr;
int zd;
int zm;
int zy;
float zjd;
int zl;
int zn;
int zj;
year = g_y;
month = g_m;
day = g_d;
zyr = year;
zd = day;
zm = month;
zy = zyr;
if((zy > 1582) || ((zy == 1582) && (zm > 10)) || ((zy == 1582) && (zm == 10) && (zd > 14)))
{
zjd = ((1461 * (zy + 4800 + ((zm - 14) / 12))) / 4)
+ ((367 * (zm - 2 - 12 * (((zm - 14) / 12)))) / 12)
- ((3 * (((zy + 4900 + ((zm - 14) / 12)) / 100))) / 4) + zd - 32075;
}
else
{
zjd = 367 * zy - ((7 * (zy + 5001 + ((zm - 9) / 7))) / 4)
+ ((275 * zm) / 9) + zd + 1729777;
}
zl = zjd - 1948440 + 10632;
zn = ((zl - 1) / 10631);
zl = zl - 10631 * zn + 354;
zj = (((10985 - zl) / 5316)) * ((int)((50 * zl) / 17719))
+ ((zl / 5670)) * ((int)((43 * zl) / 15238));
zl = zl - (((30 - zj) / 15)) * (((17719 * zj) / 50))
- ((zj / 16)) * (((15238 * zj) / 43)) + 29;
zm = ((24 * zl) / 709);
zd = zl - ((709 * zm) / 24);
zy = 30 * zn + zj - 30;
*h_y = zy;
*h_m = zm;
*h_d = zd;
}
Assuming this is for a Mac (Cocoa) or iOS (Cocoa Touch) app, since that's where you see Objective C most often, then you can just do something like this:
// Create a Gregorian Calendar
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
// Set up components of a Gregorian date
NSDateComponents *gregorianComponents = [[NSDateComponents alloc] init];
gregorianComponents.day = 4;
gregorianComponents.month = 12;
gregorianComponents.year = 2010;
// Create the date
NSDate *date = [gregorianCalendar dateFromComponents:gregorianComponents];
[gregorianComponents release];
[gregorianCalendar release];
// Then create an Islamic calendar
NSCalendar *hijriCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCivilCalendar];
// And grab those date components for the same date
NSDateComponents *hijriComponents = [hijriCalendar components:(NSDayCalendarUnit |
NSMonthCalendarUnit |
NSYearCalendarUnit)
fromDate:date];
NSLog(@"[In Hijri calendar ->] Day: %ld, Month: %ld, Year:%ld",
[hijriComponents day],
[hijriComponents month],
[hijriComponents year]);
[hijriCalendar release];
If all you want is the current date, then you can skip setting up the gregorian date altogether and just do this:
// Create an Islamic calendar
NSCalendar *hijriCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar];
// And grab the date components for the current date
NSDateComponents *hijriComponents = [hijriCalendar components:(NSDayCalendarUnit |
NSMonthCalendarUnit |
NSYearCalendarUnit)
fromDate:[NSDate date]];
[hijriCalendar release];
这篇关于回历(伊斯兰)日历的问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!