如何在PHP中将默认日期设置为波斯日期?

问题描述 投票:0回答:1

如何在PHP中将默认日期设置为波斯日期?

比方说,如果我回复此功能日期('Y-m-d'),那么它将显示2018-03-05但我希望波斯日期为1396-12-14。请帮忙

php datepicker timezone jquerydatetimepicker persian-calendar
1个回答
2
投票

请检查:http://php.net/manual/en/intldateformatter.create.php

<?php

// date_default_timezone_set('Asia/Tehran');

$now = new DateTime();

$formatter = new IntlDateFormatter(
                "fa_IR@calendar=persian", 
                IntlDateFormatter::FULL, 
                    IntlDateFormatter::FULL, 
                'Asia/Tehran', 
                IntlDateFormatter::TRADITIONAL, 
                "yyyy-MM-dd");

// It is now: 1396-12-14
echo 'It is now: ' . convert_to_number($formatter->format($now)) ."<br />"; 

// It is now: ۱۳۹۶-۱۲-۱۴
echo 'It is now: ' . $formatter->format($now) ."<br />"; 


// convert to number
function convert_to_number($string) {
    $persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
    $arabic = ['٩', '٨', '٧', '٦', '٥', '٤', '٣', '٢', '١','٠'];

    $num = range(0, 9);
    $convertedPersianNums = str_replace($persian, $num, $string);
    $englishNumbersOnly = str_replace($arabic, $num, $convertedPersianNums);

    return $englishNumbersOnly;
}
© www.soinside.com 2019 - 2024. All rights reserved.