1. 설명
- 시간 정보를 담는 객체

2. 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>변경 타이틀</title>
<!--타이틀 변경(참고:https://hkand.blogspot.com/2023/01/html5.html)-->
</head>
<body>
<h3>Date 객체</h3>
<hr>
<script>
let now = new Date();
document.write("현재 시간 : " + now.toLocaleString() + "<br><hr>");
document.write(now.getFullYear() + "year<br>");
document.write(now.getMonth() + 1 + "month<br>");
document.write(now.getDate() + "day<br>");
document.write(now.getHours() + "hours<br>");
document.write(now.getMinutes() + "minutes<br>");
document.write(now.getSeconds() + "seconds<br>");
document.write(now.getMilliseconds() + "milliseconds<br><hr>");
</script>
</body>
</html>
|
3. 기타
- getMonth()는 0부터 11를 반환하기 때문에 1을 더해줘야 함.
4. 참고
- https://www.w3schools.com/jsref/jsref_obj_date.asp
끝.