날짜 포맷(date.format)

JooKit 주킷 2021. 5. 11. 10:59
목차 접기
728x90
반응형

모두 참고용

  let date = new Date()
  let year = date.getFullYear()
  let month = date.getMonth() + 1
  month = month >= 10 ? month : '0' + month
  let day = date.getDate()
  day = day >= 10 ? day : '0' + day
  let hour = date.getHours()
  hour = hour >= 10 ? hour : '0' + hour
  let min = date.getMinutes()
  let sec = date.getSeconds()
  sec = sec >= 10 ? sec : '0' + sec

  let purchaseDay = year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec

내가 참고할 용도

//포맷 변경
var tDate = new Date(data.createAt);

//tDate.setHours(tDate.getHours() + 9)
// 서버 시간과 맞지 않아 변경하려고 했지만, 아래 작업을 통해서 한국시간과 동일해짐
let year = tDate.getFullYear()      
let month = tDate.getMonth() + 1
month = month >= 10 ? month : '0' + month
let day = tDate.getDate()
day = day >= 10 ? day : '0' + day
let hour = tDate.getHours()
hour = hour >= 10 ? hour : '0' + hour
let min = ("00" + tDate.getMinutes()).slice(-2); // 초 2자리 지정
let sec = tDate.getSeconds()
sec = sec >= 10 ? sec : '0' + sec

let purchaseDay = year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec


$("#createAt").val(String(purchaseDay).replace("T", " ").replace("Z", ""));
728x90
반응형
LIST