在json bootstrap日历中将日期转换为字符串

时间:2015-11-14 06:52:51

标签: php json twitter-bootstrap calendar strtotime

我在使用bootstrap日历时遇到问题。 event.json.php的例子给我一个这样的代码:"id": "293", "title": "This is warning class event with very long title to check how it fits to evet in day view", "url": "http://www.example.com/", "class": "event-warning", "start": "1362938400000", "end": "1363197686300" 我尝试转换"开始"到目前为止。结果与例子不一样。然后,我尝试从数据库中提供一个日期字符串,但它不起作用。所以,当我尝试将1363197686300转换为日期时,结果并不像我在想。任何人都可以帮我解决这个问题吗? 如果你和我的英语混淆,请随时问我。 T_T:)

这是我的代码。我只是重用了events.json.php的样本我只是循环代码并从数据库中提取值。

{
"success": 1,
"result": [
<?php include "config\conn.php";
                    $no = 1;
                    $sql="SELECT * from tbl_thread";
                    $query = mysql_query($sql);
                    $jmlh_evnt = mysql_num_rows($query);
                    while ($row=mysql_fetch_assoc($query)){
                        if($no == $jmlh_evnt){
    echo '{
        "id": "'.$row['id_thread'].'",
        "title": "'.$row['judul'].'",
        "url": "http://www.example.com/",
        "class": "'.$row['status'].'",
        "start": "'.date("Y/m/d H:i:s", $row['tgl_event']).'",
        "end":   "'.date("Y/m/d H:i:s", $row['selesai_event']).'"
        }'; }
    else {
    echo '{
        "id": "'.$row['id_thread'].'",
        "title": "'.$row['judul'].'",
        "url": "http://www.example.com/",
        "class": "'.$row['status'].'",
        "start": "'.date("Y/m/d H:i:s", $row['tgl_event']).'",
        "end":   "'.date("Y/m/d H:i:s", $row['selesai_event']).'"
    },';

    }

}$no++; ?>
    {
        "id": "",
        "title": "",
        "url": "",
        "class": "",
        "start": "2015-11-14 12:00:00",
        "end":   "2015-11-15 12:00:00"
    }
]

}

  

{&#34;成功&#34;:1,&#34;结果&#34;:[{&#34; id&#34;:&#34; 1&#34;,&#34;标题&# 34;:&#34;晚宴与Rektor&#34;,&#34; url&#34;:&#34; http://www.example.com/&#34;,&#34; class&#34;:&#34 ; event-info&#34;,&#34; start&#34;:&#34; 2015/10/11 12:00:00&#34;,&#34; end&#34;:&#34; 2015 / 10/12 12:00:00&#34; },{&#34; id&#34;:&#34; 2&#34;,&#34; title&#34;:&#34; test&#34;,&#34; url&#34;:&# 34; http://www.example.com/&#34;,&#34; class&#34;:&#34; event-warning&#34;,&#34; start&#34;:&#34; 2015/11/12 00:00:00&#34;,&#34;结束&#34;:&#34; 2015/11/12 00:00:00&#34; },{&#34; id&#34;:&#34;&#34;,&#34; title&#34;:&#34;&#34;,&#34; url&#34;:&# 34;&#34;,&#34; class&#34;:&#34;&#34;,&#34; start&#34;:&#34; 2015-11-14 12:00:00&#34 ;,&#34;结束&#34;:&#34; 2015-11-15 12:00:00&#34; }]}

1 个答案:

答案 0 :(得分:1)

您需要从字符串中提取数字,并将其传递给Date构造函数:

var date = new Date(parseInt(start));

然后你可以格式化日期

var newDate = dateFormat(date, "mm/dd/yyyy");