본문 바로가기
Never Ending Study/JAVASCRIPT

날짜 형식 및 세부적으로 가져오기

by 건방진참새 2018. 12. 27.
new Date().toISOString()
"2016-02-18T23:59:48.039Z"
new Date().toISOString().split('T')[0];
"2016-02-18"
new Date().toISOString().replace('-', '/').split('T')[0].replace('-', '/');
"2016/02/18"

new Date().toLocaleString().split(',')[0]
"2/18/2016"
function js_yyyy_mm_dd_hh_mm_ss () {
  now = new Date();
  year = "" + now.getFullYear();
  month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
  day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
  hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
  minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
  second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
  return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}
example alert message: 2011-05-18 15:20:12


'Never Ending Study > JAVASCRIPT' 카테고리의 다른 글

두 일자 사이의 날짜들 가져오기  (0) 2019.01.24
CLOSE DIV ON CLICK OUTSIDE OF IT  (0) 2019.01.08
ajax 통신 간소화  (0) 2018.12.10
ajax charset 설정하여 POST 하기  (0) 2018.04.03
JS 배열 순서 sort 하기  (0) 2018.03.30