2015-10-03 77 views
-1

在我的数据库中,当我插入使用strtotime转换为时间戳的日期和时间时,它就像“1444600800”,我也有一段时间为某个服务转换为相同的过程,“1443740700”,现在我使用https://github.com/almasaeed2010/AdminLTE,以其http://fullcalendar.io/,在日历事件,它被编写这样一个事件:如何在Unix时间戳中提取月份,日期,年份,小时?

events: [ 
        { 
         title: 'All Day Event', 
         start: new Date(y, m, 1), 
         end: new Date(y, m, d, 13, 30), 
         backgroundColor: "#f56954", //red 
         borderColor: "#f56954" //red 
        } ] 

我编写它像这样,但没有成功:

events: 
    [ 
    <?php $event_query = mysql_query("select *,TIME_FORMAT (`appoint_date`, '%H:%i') from appointment INNER JOIN service,user where appointment.user_id = user.user_id and service.service_id = appointment.service_id")or die(mysql_error()); 
      while($event_row = mysql_fetch_array($event_query)){ 


    ?> 
    { 
     title : '<?php echo $event_row['firstname']; ?> ', 
     start : <?php echo $event_row['appoint_date']; ?>, 
     end : <?php echo $event_row['duration']; ?>, 
     allDay: false, 
     backgroundColor: "#3c8dbc", //Primary (light-blue) 
     borderColor: "#3c8dbc" //Primary (light-blue) 
    }, 
    <?php } ?> 
    ] 

我想提取时间戳中的日期,月份,小时,我可以添加我的timesta的小时值从服务持续时间到日期和时间时间戳,并将其编码为样本。用公式:

​​

该怎么办?

回答

1
start: new Date(<?=$event_row['appoint_date']?>000) 

请注意,您需要通过1000乘以(在上面,只需添加三个零),因为JS时间戳以毫秒为单位,而在PHP他们在几秒钟。

+0

嘿,是的,我想你可以像这样添加三个零... :-) –

+0

如何提取持续时间并将其添加到时间戳?所以我可以将其结果插入到最后:? –

0

构造函数Date有一个单参数版本,它接受自纪元以来的毫秒数。 Unix时间戳通常是秒,因为最时代(你的是,无论如何),所以:

start : new Date(<?php echo $event_row['appoint_date']; ?> * 1000), 

...将建立在客户端的相关日期(注意* 1000)。

+0

我正在考虑给日期添加一个时间值,是否有可能将一个小时的时间戳添加到日期?我还需要编码结束:像这样结束:<?php echo $ event_row ['duration + appoint_date']; ?>,就像那样 –

相关问题