[英]Converting a date from a calendar type to another type
我需要一个函数来将波斯日历中的日期转换成对应的公历日期。 我按照此页面的示例#3编写了以下函数。 不幸的是,它有效吗? 怎么了 使用Intl扩展名的正确方法是什么?
function convert($time, $fromCalendar = 'gregorian', $toCalender = 'persian', $fromFormat = 'yyyy-MM-dd HH:mm:ss',
$toFormat = 'yyyy-MM-dd HH:mm:ss', $timezone = null, $local = 'fa_IR')
{
$formatter = IntlDateFormatter::create($local . '@calendar:' . $fromCalendar, null, null, $timezone, null, $fromFormat);
$formatter->setCalendar(IntlCalendar::createInstance(null, $local . '@calendar:' . $toCalender));
$output = $formatter->format($formatter->parse($time));
if ($output) return $output;
return $formatter->getErrorMessage();
}
可以在这里找到有关Intl的很好的介绍: http : //devzone.zend.com/1500/internationalization-in-php-53/
这似乎很有希望: http : //www.phpclasses.org/package/4852-PHP-Convert-and-format-dates-of-the-Persian-calendar.html
然后,您将要做:
$persian=new persian_date();
echo $persian->date('y-m-d H:i:s');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.