Heojju

[JavaScript] Date 포맷 본문

웹개발/JavaScript

[JavaScript] Date 포맷

우주별 2017. 5. 12. 09:32
<script>
var today = new Date();
var year = today.getFullYear().toString();
var month = (today.getMonth()+1).toString();
var day = today.getDate().toString();
var mmChars = month.split('');
var ddChars = day.split('');

var datestring = year + '-' + (mmChars[1]?month:"0"+mmChars[0]) + '-'
+ (ddChars[1]?day:"0"+ddChars[0]);
</script>




'웹개발 > JavaScript' 카테고리의 다른 글

[JavaScript] rgb to hex  (0) 2017.06.08
[JavaScript] 현재 focus 객체  (0) 2017.06.08
[JavaScript] localStorage / sessionStorage  (0) 2017.05.09
[JavaScript] setTimeout  (0) 2017.03.09
[JavaScript] 현재 url 가져오기  (0) 2017.01.31