js 格式化时间

 

 写一个过滤器

 

 

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; }

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

posted @ 2020-07-01 11:49  金陵彭于晏  阅读(187)  评论(0编辑  收藏  举报