For an easy way, you must have intl
extension installed on your server and your php version must be higher that 5.4
. If it is, you easily can make an IntlCalendar
instance with Persian calendar parameters:
$date = IntlCalendar::createInstance(
'Asia/Tehran',
'fa_IR@calendar=persian'
);
set your datetime:
$date->set(1395, 5, 15, 19, 17, 11); // Notice that month number begin from 0 not 1.
then make an instance of IntlDateFormatter
with Gregorian calendar -or every calendar you want:
$intlDateFormatter = new IntlDateFormatter(
"en_US", // string $locale
IntlDateFormatter::FULL, // int $datetype
IntlDateFormatter::FULL, // int $timetype
'Asia/Tehran', // mixed $timezone
IntlDateFormatter::GREGORIAN, // mixed $calendar
'yyyy/MM/dd HH:mm:ss' // string $pattern
);
and use toDateTime
method of that for showing your desired date:
var_dump($intlDateFormatter->format($date));
// /srv/http/test/DateTime.php:29:
// string(19) "2016/09/05 19:17:11"
P.S.: I write a small library for converting date that can be found here: https://github.com/meysampg/intldate, Also if you only want to represent date on other system, you can use IntlDateBehavior.