时间戳转换为时间

5年以前  |  阅读数:433 次  |  编程语言:JavaScript 
//默认为当前时间转换结果
//isMs 为时间戳是否为毫秒
function timestampToTime(timestamp = Date.parse(new Date()), isMs = true) {
  const date = new Date(timestamp * (isMs ? 1 : 1000));
  return `${date.getFullYear()}-${
    date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1
  }-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8