js将时间戳处理为年月日时分秒格式

js处理时间格式

将时间戳处理为 年月日格式

const handler = (timestamp) => {
  let date = new Date(parseInt(timestamp)),
    y = date.getFullYear(),
    m = date.getMonth() + 1,
    d = date.getDate()
  if (m > 9) {
    m = m
  } else {
    m = "0" + m
  }
  if (d > 9) {
    d = d
  } else {
    d = "0" + d
  }
  return "" + y + "-" + m + "-" + d
}

将时间戳处理为为 年月日时分秒格式

const getTime_s = (timestamp) => {
    let date = new Date(parseInt(timestamp))
    // let date = new Date(parseInt(timestamp) * 1000)
    let Year = date.getFullYear()
    let Moth =
      date.getMonth() + 1 < 10
        ? "0" + (date.getMonth() + 1)
        : date.getMonth() + 1
    let Day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
    let Hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
    let Minute =
      date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
    let Sechond =
      date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
    let GMT =
      Year +
      "-" +
      Moth +
      "-" +
      Day +
      "   " +
      Hour +
      ":" +
      Minute +
      ":" +
      Sechond
    return GMT
  }

你可能感兴趣的:(JavaScript,javascript,前端)