Converting Gregorian date to Hijri date

前端 未结 3 991
情深已故
情深已故 2020-12-08 15:56

How do you convert Gregorian dates to Islamic Hijri dates using JavaScript?

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 16:37

    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 كل الحقوق محفوطة لـ ... ©

     م -  هـ
    

    you will get: كل الحقوق محفوطة لـ ... © 2014 م - 1435 هـ

    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

    Finally, if you need to convert to UmAlQura date, simply try this line of code:

    let _date = new Date('7/10/2019').toLocaleDateString('ar-SA').format('DD/MM/YYYY');
    
    console.log(_date);
    

    will return : ٧‏/١١‏/١٤٤٠ هـ

提交回复
热议问题