doudouji2016 2014-04-28 18:47
浏览 47

将日期转换为毫秒到目前为止

I ran into a strange issue. I am sending a date that I converted to milliseconds using Javascript to my controller. There, I convert the milliseconds to a time stamp in PHP. It seems to get the date part of it right, but the time is totally off. Can anyone please tell me what am I missing? The code is below.

javascript

var d = new Date("13 October 2014 11:13:00");    
document.write(d.getTime() + " milliseconds since 1970/01/01");

result

1413191580000

php

echo date("Y-m-d H:i:s", 1413191580000/1000);

result

2014-10-13 02:13:00
  • 写回答

2条回答 默认 最新

  • dpb75177 2014-04-28 18:50
    关注

    I'm guessing this is happening because you have a date with a different timezone returned from the client than the server. JavaScript's Date.prototype.getTime() returns a UTC timestamp according to the ECMAScript standard (§15.9.1.1). Standardize the time zones between client and server and then you can have dates be the same in both. I always deal with dates in UTC on the server and then do client side timezone localizations.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算