Date 객체는 JavaScript 언어에 내장된 데이터 유형입니다. Date 객체는 아래와 같이 새로운 Date( )로 생성됩니다.
Date 개체가 생성되면 여러 메서드를 사용하여 해당 개체에 대해 작업할 수 있습니다. 대부분의 방법을 사용하면 현지 시간이나 UTC(유니버설 또는 GMT) 시간을 사용하여 개체의 연도, 월, 일, 시, 분, 초 및 밀리초 필드를 가져오고 설정할 수 있습니다.
Date 객체의 now() 함수는 1 st 이후의 밀리초 수를 반환합니다. 1970년 1월.
구문
구문은 다음과 같습니다.
Date.now();
예시
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var currentDate = Date.now();
var birthDate = Date.parse('29 sep 1989 00:4:00 GMT');
document.write(currentDate);
document.write(", "+birthDate+", ");
document.write(currentDate - birthDate);
</script>
</body>
</html> 출력
1537780591654, 623030640000, 914749951654
예시
이 함수를 사용하여 현재 날짜를 가져올 수 있지만 형식이 지정된 날짜를 가져오기 위해 1970년 1월 1일부터 밀리초 단위의 숫자를 반환하므로 얻은 값을 Date 생성자에 전달합니다.
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var currentDate = Date.now();
document.write(currentDate);
document.write("<br>");
document.write(Date(currentDate).toString());
</script>
</body>
</html> 출력
1539758885099 Wed Oct 17 2018 12:18:05 GMT+0530 (India Standard Time)