Skip to content

Instantly share code, notes, and snippets.

@hariadi
Last active January 9, 2017 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hariadi/81780477001f498ada2a6f7ec928af33 to your computer and use it in GitHub Desktop.
Save hariadi/81780477001f498ada2a6f7ec928af33 to your computer and use it in GitHub Desktop.
Islamic date using pure PHP
<?php
/*
* Requirement: PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0
* Ubuntu:
* apt-get install php5-intl
*
* RedHat:
* yum install libicu libicu-devel.x86_64
*/
// full date
$DateTime = new DateTime();
$date = new IntlDateFormatter(
'ms_MY@calendar=islamic',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Asia/Kuala_Lumpur',
IntlDateFormatter::TRADITIONAL,
);
echo $date->format($DateTime);
echo $date->getPattern();
// custom format
$DateTime = new DateTime();
$date = new IntlDateFormatter(
'ms_MY@calendar=islamic',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Asia/Kuala_Lumpur',
IntlDateFormatter::TRADITIONAL,
'd MMMM y'
);
echo $date->format($DateTime);
echo $date->getPattern();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment