Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Unix时间戳中提取月、日、年、小时?_Javascript_Mysql_Timestamp_Fullcalendar_Strtotime - Fatal编程技术网

Javascript 如何在Unix时间戳中提取月、日、年、小时?

Javascript 如何在Unix时间戳中提取月、日、年、小时?,javascript,mysql,timestamp,fullcalendar,strtotime,Javascript,Mysql,Timestamp,Fullcalendar,Strtotime,在我的数据库中,当我使用strotime插入转换为时间戳的日期和时间时,它类似于“1444600800”,并且我还有一个特定服务的持续时间,该服务被转换为同一进程“1443740700”,现在我使用它,在日历事件中,它的代码如下: events: [ { title: 'All Day Event', start: new Date(y, m, 1),

在我的数据库中,当我使用strotime插入转换为时间戳的日期和时间时,它类似于“1444600800”,并且我还有一个特定服务的持续时间,该服务被转换为同一进程“1443740700”,现在我使用它,在日历事件中,它的代码如下:

  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 } ?>
    ]
怎么办

开始:新日期(000)
start: new Date(<?=$event_row['appoint_date']?>000)

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

日期构造函数有一个单参数版本,它接受从纪元开始的毫秒。Unix时间戳通常是从纪元开始的秒数(无论如何,您的时间戳是秒数),因此:

开始:新日期(*1000),

…将在客户端创建相关日期(注意
*1000
)。

嘿,是的,我想您可以这样添加三个零…:-)如何提取持续时间并将其添加到时间戳?因此,我可以将其结果插入结尾:?我正在考虑为日期添加一个时间值,是否可以为日期添加一个小时持续时间时间戳?我还需要编码结尾:像这样的结尾:,类似的东西
start: new Date(<?=$event_row['appoint_date']?>000)
start : new Date(<?php echo $event_row['appoint_date']; ?> * 1000),