자바스크립트 날짜 시간 input 박스에 넣는 방법 입니다
아래와 같이 스크립트를 넣어주고 바디부분에 로드시에만 값을 넣게 하면 됩니다
년,월,시간,분,초 전부 들어 있으니 원하는 값만 바꿔서 변경해도 됩니다.
<html>
<head>
<title>시간</title>
<script type="text/javascript">
(function today(){
var _date = new Date(),
_year = _date.getFullYear(),_month = _date.getMonth()+1,
_day = _date.getDate(),
_hours = _date.getHours(),
_minutes = _date.getMinutes(),
_ampm = _hours < 13 ? "오전" : "오후";
_month = _month < 10 ? "0"+_month : "";
_day = _day < 10 ? "0"+_day : "";
_hours = _hours > 12 ? "0"+(_hours - 12) : "0"+_hours;
_time = _year + _month + _day;
}());
</script>
</head>
<body onLoad="document.all('def_date').value=_time">
<input type="text" name="def_date">
</body>
</html>
'프로그래밍 > HTML, CSS' 카테고리의 다른 글
HTML - <font>, <p> , <div>, <a> (0) | 2020.06.04 |
---|---|
자바스크립트 웹페이지 팝업 띄우기 (0) | 2020.05.12 |
html th td 줄바꿈 제어하기 nowrap (0) | 2020.04.15 |
크롬에서 css 적용안될 때 이용법 (0) | 2020.04.15 |
html, css table 에서 td 최소 사이즈 넣는 법 (0) | 2020.04.09 |
댓글