Php 如何从我的IntlDateFormatter()函数中获取特定结果。?
我有此功能将公历日期转换为Jalali(波斯语)日期: 当我把它叫做toJalali(time())时,它就是给我完整的日期Php 如何从我的IntlDateFormatter()函数中获取特定结果。?,php,function,datetime-format,Php,Function,Datetime Format,我有此功能将公历日期转换为Jalali(波斯语)日期: 当我把它叫做toJalali(time())时,它就是给我完整的日期(1397-8-17ه.ش… 如何从上述函数中获取我的特定日期格式 我知道可以在构造函数中设置格式选项: $fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tehran', IntlDateFormatt
(1397-8-17ه.ش…
如何从上述函数中获取我的特定日期格式
我知道可以在构造函数中设置格式选项:
$fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL, 'MM/dd/yyyy');
但是当我需要其他时间格式时呢
只喜欢年:(yyyy)
或(EEEE/yyyy/MM)
等。所以我必须为每个日期格式编写单独的函数
谢谢。要更改图案,可以使用以下方法:
$fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL, 'MM/dd/yyyy');
$fmt->setPattern('EEEE/yyyy/MM');
echo $fmt->format(0);
function toJalali ($date, $pattern = null)
{
$fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL);
if ($pattern){
$fmt->setPattern($pattern);
}
return $fmt->format($date);
}
您的函数如下所示:
$fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL, 'MM/dd/yyyy');
$fmt->setPattern('EEEE/yyyy/MM');
echo $fmt->format(0);
function toJalali ($date, $pattern = null)
{
$fmt = new IntlDateFormatter("fa_IR@calendar=persian", IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tehran', IntlDateFormatter::TRADITIONAL);
if ($pattern){
$fmt->setPattern($pattern);
}
return $fmt->format($date);
}
谢谢,但是你对保留该功能有什么建议?@MehdiBoveiri再次检查答案