Skip to content

Instantly share code, notes, and snippets.

@mohamedmansour
Created May 7, 2021 10:02
Show Gist options
  • Save mohamedmansour/4c0dcb1e2a929b4da99a169e469dacf0 to your computer and use it in GitHub Desktop.
Save mohamedmansour/4c0dcb1e2a929b4da99a169e469dacf0 to your computer and use it in GitHub Desktop.
Convert Gregorian Date to Islamic Date (Hijri)
/**
* 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