美文网首页
时间戳或者中国标准时间转换成标准时间(yyyy-MM-DD)

时间戳或者中国标准时间转换成标准时间(yyyy-MM-DD)

作者: 圆小鑫鑫 | 来源:发表于2018-11-02 15:32 被阅读0次

标准日期:2018-10-24 或 2018-10-24 20:00:00
中国标准时间:Wed Oct 24 2018 20:00:00 GMT+0800 (中国标准时间)
时间戳:1540382400
毫秒数:1540382400000
注意:时间戳*1000就是毫秒数

此时间转换方法可将 时间戳转换成 标准时间(YY-MM-DD hh:mm:ss)
也可将 中国标准时间 转换成 标准时间
timestampToTime(timestamp){
      var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
      var Y = date.getFullYear() + '-';
      var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
      var D = date.getDate() + ' ';
      var h = (date.getHours() < 10 ? '0'+(date.getHours()) : date.getHours()) + ':' ;
      var m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':' ;
      var s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds());
      return Y+M+D+h+m+s;
}
      this.timestampToTime(time);

相关文章

网友评论

      本文标题:时间戳或者中国标准时间转换成标准时间(yyyy-MM-DD)

      本文链接:https://www.haomeiwen.com/subject/jnlcxqtx.html