问题描述
我有一个PHP脚本输出数据的数组。然后使用json_encode()函数将其转换为JSON。我的问题是我的数组中有一个日期,它的格式不正确。如何在PHP中进行转换? $ newticket ['ThreadID'] = $ addticket;
$ newticket ['Subject'] = $ subject;
// $ newticket ['DateCreated'] = date('d-m-Y G:H');
而不是上述日期,我需要javascript功能的等同文学
当我输出上面我得到以下Fri Jun 01 2012 11:08:48 GMT + 0100(GMT Daylight Time)但是,如果我将PHP日期格式设置为相同,则JavaScript拒绝。困惑...
任何人都可以帮助?
可能只是使用时间戳记
$ newticket ['DateCreated'] = strtotime('now');
然后将其转换为Javascript日期
//确保从unix时间戳转换
var now = new Date(dateFromPHP * 1000);
I have a PHP script that outputs an array of data. This is then transformed into JSON using the json_encode() function. My issue is I have a date within my array and its is not in the correct javascript format. How can I convert this within PHP so it is?
$newticket['ThreadID'] = $addticket;
$newticket['Subject'] = $subject;
//$newticket['DateCreated'] = date('d-m-Y G:H');
Instead of the above fo rthe date I need the equivilant of the javascript function
When I output the above I get the following "Fri Jun 01 2012 11:08:48 GMT+0100 (GMT Daylight Time)" However, If I format my PHP date to be the same, javascript rejects it. Confused...
Can anyone help?
You should probably just use a timestamp
$newticket['DateCreated'] = strtotime('now');
Then convert it to a Javascript date
// make sure to convert from unix timestamp
var now = new Date(dateFromPHP * 1000);
这篇关于将PHP日期转换为JavaScript日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!