Maison  >  Questions et réponses  >  le corps du texte

javascript - 如何判断传入的时间是毫秒还是秒?

如何判断传入的时间是毫秒还是秒?
是判断传入的时间长度吗?
1467340272长度一样是以秒为单位的,和1467340272864长度一样是以毫秒为单位的?

ringa_leeringa_lee2749 Il y a quelques jours1389

répondre à tous(5)je répondrai

  • 迷茫

    迷茫2017-04-11 11:21:49

    js 时间戳是毫秒长度是13位
    秒的时间戳是10位,例如php时间戳
    判断下长度就可以知道是毫秒还是秒了

    var a =String(1467340272864) ;
    console.log(a.length)

    répondre
    0
  • 天蓬老师

    天蓬老师2017-04-11 11:21:49

    理论上长度判断下就好,或者让后台给补000。
    比如php时间戳是10位的,所以你前端直接判断数字长度即可,10位就加3个0。

    répondre
    0
  • ringa_lee

    ringa_lee2017-04-11 11:21:49

    如果是通过接口获得的数据,不应该自己判断,接口应该定义好是秒还是毫秒

    répondre
    0
  • ringa_lee

    ringa_lee2017-04-11 11:21:49

    函数的功能是什么?

    répondre
    0
  • PHPz

    PHPz2017-04-11 11:21:49

    秒和毫秒相差1000倍,这个很好判断吧

    répondre
    0
  • Annulerrépondre