날짜 문자열에서 날짜 개체를 만들려면 다음과 같은 문자열을 추가하기만 하면 됩니다. -
var date = new Date(2018,1,1);
예시
다음 코드를 실행하여 날짜 문자열에서 날짜 개체를 만들 수 있습니다. 여기에서 월은 JavaScript에서 1월은 0, 2월은 1 등으로 인덱싱됩니다. -
<html>
<head>
<title>JavaScript Dates</title>
</head>
<body>
<script>
var date;
date = new Date(2018,0,1);
document.write("Current Date: "+date);
</script>
</body>
</html> 출력
Current Date: Mon Jan 01 2018 00:00:00 GMT+0530 (India Standard Time)