js把时间转换为时间戳

Myth丶恋晨 2023-02-11 07:28 95阅读 0赞
  1. var timer = Date.now();console.log(timer);
  2. var timestamp1 = Date.parse(new Date());
  3. var timestamp2 = (new Date()).valueOf();
  4. var timestamp3 = new Date().getTime();
  5. console.log(timestamp1);
  6. console.log(timestamp2);
  7. console.log(timestamp3);
  8. var strtime = '2014-04-23 18:55:49:123'; //把日期转换为时间戳;
  9. var date = new Date(strtime);
  10. console.log(date);
  11. var date = new Date(1577688324100); //把时间戳转换为日期
  12. Y = date.getFullYear() + '-';
  13. M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
  14. D = date.getDate() + ' ';
  15. h = date.getHours() + ':';
  16. m = date.getMinutes() + ':';
  17. s = date.getSeconds();
  18. console.log(Y+M+D+h+m+s);

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,95人围观)

还没有评论,来说两句吧...

相关阅读