简体   繁体   English

php jdate无法正常工作

[英]php jdate does not work properly

I have an array of dates as a MySQL query result. 我有一个日期数组作为MySQL查询结果。 These dates are Gregorian and I have converted them to Persian with jdate function in php as below: 这些日期是公历日期,我已使用php jdate函数将它们转换为波斯语,如下所示:

foreach ($data['items'] as $key => $value) 
{
        $val1 = strtotime($value->sub_date);
        $value->sub_date =jdate('y-m-d H:i',$val1);

        if (isset($value->unsub_date)) 
        {
                $val2 = strtotime($value->unsub_date);
                $value->unsub_date =jdate('y-m-d H:i',$val2);
        }

        $val3 = strtotime($value->first_sub);
        $value->first_sub =jdate('y-m-d H:i',$val3);

}

This code works fine but just the first element is not converted properly, The hour and second of first Persian date is incorrect but others are OK. 该代码可以正常工作,但仅第一个元素未正确转换。第一个波斯语日期的小时和秒不正确,但其他都可以。

you try change your code and other case to the same.. 您尝试将代码和其他大小写更改为相同。

    $val1 = strtotime($value->sub_date);
    $value->sub_date =jdate('y-m-d H:i',$val1);

To

    $value->sub_date = date('y-m-d H:i',strtotime($value->sub_date));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM