首页 > Web开发 > 详细

js 格式化时间

时间:2020-07-01 12:32:18      阅读:66      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 写一个过滤器

技术分享图片

 

 

getTime(item) {
      const date = new Date(
     //这一步是根据我后端返回的时间格式处理的,可选用  item.replace(
/\-/g, "/").substring(0, item.indexOf(".")) ); const Y = date.getFullYear() + "-"; const M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-"; const D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " "; const h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":"; const m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":"; const s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); return Y + M + D + h + m + s; }

拿走不谢,我是金陵彭于晏我们下期再见!!!

js 格式化时间

原文:https://www.cnblogs.com/lq2333/p/13218399.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!