Created
May 7, 2021 10:02
-
-
Save mohamedmansour/4c0dcb1e2a929b4da99a169e469dacf0 to your computer and use it in GitHub Desktop.
Convert Gregorian Date to Islamic Date (Hijri)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Uses JavaScripts Internationalization to convert a gregorian date into | |
* an islamic hijri date. The W3C Spec included a format "ca-islamic" which | |
* makes this all happen. | |
*/ | |
export function getHijriDate(date = new Date()) { | |
const locale = navigator.language | |
return new Intl.DateTimeFormat(locale + '-u-ca-islamic', { | |
day: 'numeric', | |
month: 'long', | |
year: 'numeric' | |
}).format(date) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment