- ํ์ฌ ๋ ์ง๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ค์ํ ๋ฐฉ์์ ๋ ์ง ์ถ๋ ฅํ๊ธฐ
1. Date()์ ์๋ ๋ค์ํ ๋ฉ์๋
- .getFullYear() : ์ฐ๋
- .getMouth() : ์
- .getDate() : ์ผ
- .getHours() : ์
- .getMinutes() : ๋ถ
- .getSeconds() : ์ด
- .toDateString() : ์๋ฌธ ๋ ์ง ํ๊ธฐ ๋ฐฉ์
- .toLocalString() : ํ์ฌ ์ฌ์ฉํ๊ณ ์๋ ์ปดํจํฐ์ ๋ก์ปฌ ๋ ์ง์ ์๊ฐ
- .toLocalDateString() : ํ์ฌ ์ฌ์ฉํ๊ณ ์๋ ์ปดํจํฐ์ ๋ก์ปฌ ๋ ์ง
<body>
<script>
let now = new Date();
document.write(now + "<br>");
document.write("์ฐ๋ : " + now.getFullYear() + "<br>");
document.write("์ : " + now.getMonth() + "<br>"); //์์ด 0๋ถํฐ ์์, +1์ ํด์ค์ผ ํจ
document.write("์ผ : " + now.getDate() + "<br>");
document.write("์ : " + now.getHours() + "<br>");
document.write("๋ถ : " + now.getMinutes() + "<br>");
document.write("์ด : " + now.getSeconds() + "<br>");
document.write("<br>");
document.write("๋ ์ง๋ฅผ ๋ฌธ์์ด ํํ๋ก : " + now.toDateString() + "<br>");
document.write("๋ ์ง๋ฅผ ๋ฌธ์์ด ํํ๋ก : " + now.toLocaleString() + "<br>");
document.write(
"๋ ์ง๋ฅผ ๋ฌธ์์ด ํํ๋ก : " + now.toLocaleDateString() + "<br>"
);
</script>
</body>
- ๋ธ๋ผ์ฐ์ ์ถ๋ ฅ
- ํน์ ๋ ์ง๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ ์ง ์ถ๋ ฅํ๊ธฐ
<body>
<script>
let date = new Date(2021, 10, 26); // 10 => 11์
document.write("์ฐ๋ : " + date.getFullYear() + "<br>");
document.write("์ : ", date.getMonth() + 1, "<br>"); //์์ด 0๋ถํฐ ์์
document.write("์ผ : " + date.getDate() + "<br>");
</script>
</body>
- ์์ 0๋ถํฐ ์์์ ํ๊ธฐ๋๋ฌธ์ 10์ ๋ฃ์ผ๋ฉด ์ค์ ๋ก๋ 11์์ ๊ฐ๋ฆฌํค๋ ๊ฒ์ด ๋จ, ์ถ๋ ฅ์ 1์ ๋ํด์ผ ํจ
- ๋ธ๋ผ์ฐ์ ์ถ๋ ฅ
'JAVASCRIPT' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVASCRIPT] ์๋ฐ ์คํฌ๋ฆฝํธ ๋ด์ฅ ๊ฐ์ฒด - String() (0) | 2021.10.31 |
---|---|
[JAVASCRIPT] ์๋ฐ ์คํฌ๋ฆฝํธ ๋ด์ฅ๊ฐ์ฒด - Math() (0) | 2021.10.31 |
[JAVASCRIPT] ์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์ฒด ์ ์ธ (0) | 2021.10.31 |
[JAVASCRIPT] ์๋ฐ ์คํฌ๋ฆฝํธ ๋ฐฐ์ด (0) | 2021.10.31 |
[JAVASCRIPT] ๋ด์ฅํจ์ - prompt(), parseInt(), Number(), isNaN() (0) | 2021.10.31 |