JangBaGeum.gif

[JavaScript]Date Object에서 Year/Month/Date 얻기 본문

ETC/알고리즘 & 문법

[JavaScript]Date Object에서 Year/Month/Date 얻기

장바금 2022. 11. 17. 16:32
var dateObj = new Date();
var month = dateObj.getMonth() + 1; //months from 1-12
var day = dateObj.getDate();
var year = dateObj.getFullYear();

newdate = year + "/" + month + "/" + day;

 

 

  • getUTCMonth(), getUTCDate(), getUTCFullYear() 등과 같이 UTC가 포함된 것은 UTC기준 Date
  • 월(month)은 0부터 시작 (1월은 0, 2월은 1)
  • getDay()는 요일(0-6) getDate()는 날짜(1-31)
  • getYear()은 현재 연도에서 1900 값을 뺀 값 반환 (현재는 Deprecated)