duanmi3476 2011-04-19 19:51
浏览 32
已采纳

在JavaScript中将字符串转换为Date()

How do I convert this timestamp from php into a javascript Date() object?

This is how I grab the time:

$timestart = time();

and I parse this to a javascript function and I want to convert it into a JavaScript date object.

help, all this date stuff confuses me quite a bit.

thanks,

  • 写回答

3条回答 默认 最新

  • doushe8577 2011-04-19 19:55
    关注

    If val contains your PHP value which is

    the current time measured in the number of seconds since the Unix Epoch

    then you just need this:

    var timestart = new Date(val * 1000);
    

    JavaScript uses the same base time as UNIX systems (midnight on 01/01/1970) but measured in milliseconds rather than seconds.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ADS生成的微带线为什么是蓝色空心的
  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?
  • ¥20 求友友协助弄一下基于STC89C52单片机的声光控制灯原理图
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭