Вы находитесь на странице: 1из 5

Stack Overflow

Questions

Tags

Users

sign up
Badges

Unanswered

log in

Ask

Read this post in our app!

How to convert Gregorian date to Hijri date


5

javascript

date

gregorian-calendar

date-conversion

hijri

Does anyone know how to convert from Gregorian date to the Islamic Hijri date using JavaScript?

share

improve this question


FuNk
28

1 1 5

Amro
97.9k

2 Answers

17 147 283

Asked
Mar 3 '11 at 6:51

Edited
Jun 9 '12 at 21:36

order by votes

myRes[0] = day; //calculated day (CE)


myRes[1] = month-1; //calculated month (CE)
myRes[2] = year; //calculated year (CE)
myRes[3] = jd-1; //julian day number
myRes[4] = wd-1; //weekday number
myRes[5] = id; //islamic date
myRes[6] = im-1; //islamic month
myRes[7] = iy; //islamic year
return myRes;
}
function writeIslamicDate(adjustment) {
var wdNames = new Array("Ahad","Ithnin","Thulatha","Arbaa","Khams","Jumuah","Sabt");
var iMonthNames = new Array("Muharram","Safar","Rabi'ul Awwal","Rabi'ul Akhir",
"Jumadal Ula","Jumadal Akhira","Rajab","Sha'ban",
"Ramadan","Shawwal","Dhul Qa'ada","Dhul Hijja");
var iDate = kuwaiticalendar(adjustment);
var outputIslamicDate = wdNames[iDate[4]] + ", "
+ iDate[5] + " " + iMonthNames[iDate[6]] + " " + iDate[7] + " AH";
return outputIslamicDate;
}

This converts current computer date to hijri. And with a little modification you can achieve that this snippet change any date to
islamic
document.write(writeIslamicDate(1));

Taken from This site

share

improve this answer


Lixas
1,775

10 24

thank you for the fast reply, i will try and use this function.. =D FuNk Mar 3 '11 at 7:21
guess what, it really work.. thank you again.. =D FuNk Mar 3 '11 at 7:23

Answered
Mar 3 '11 at 7:07

Good stuff. Thanks ! The Newbie Oct 30 '11 at 21:24

Excellent, can you please tell me what this adjustment / adjust variable is used for?? AtanuCSE Jun 19 '14 at 5:19
"Adjust" variable is used to correct the shift in Hijri dates which occurs because of variable moon status and visibility on different months. Ahmed Said Apr 1 '15
at 13:41

add a comment

If you need only the year of Hijri date converted from Gregorian date (Miladi date) you can simply write this equation in javascript:
var GregorianYear = (new Date()).getFullYear();
var HijriYear = Math.round((GregorianYear - 622) * (33 / 32));

you can use this simple equation in the footer in master page like ...
<script type="text/javascript">document.write((new Date()).getFullYear())</script> - <script type="text/javascript">var y = (new Date()).getFullYear();
var h = Math.round((y - 622) * (33 / 32));document.write(h)</script>

you will get: 1435 - 2014 ...


you can also use C# embedded in asp page as:
<%= DateTime.Now.Year %> - <%= Math.Round((DateTime.Now.Year - 622) * 1.03125) %>

will return : 2014 - 1436

share

improve this answer


Zakaria
421 5

11

Answered
Aug 8 '14 at 15:49

Edited
Nov 15 '14 at 13:01

Your Answer

log in
or
Name

Email

By posting your answer, you agree to the privacy policy and terms of service.

Post Your Answer

meta chat tour help blog privacy policy legal contact us full site
Download the Stack Exchange Android app
2016 Stack Exchange, Inc

Вам также может понравиться