ES6-날짜

그만큼 Date objectJavaScript 언어에 내장 된 데이터 유형입니다. 날짜 개체는 새로운Date () 다음 구문에 표시된대로.

Date 객체가 생성되면 여러 메서드를 사용하여 작업 할 수 있습니다. 대부분의 메서드를 사용하면 로컬 시간 또는 UTC (범용 또는 GMT) 시간을 사용하여 개체의 년, 월, 일,시, 분, 초 및 밀리 초 필드를 가져오고 설정할 수 있습니다.

ECMAScript 표준은 Date 객체가 1970 년 1 월 1 일 전후 1 억일 이내의 모든 날짜와 시간을 밀리 초 단위로 나타낼 수 있도록 요구합니다. 이는 플러스 또는 마이너스 273,785 년 범위이므로 JavaScript는 275755 년까지의 날짜와 시간을 나타낼 수 있습니다.

다음 구문 중 하나를 사용하여 다음을 사용하여 Date 객체를 만들 수 있습니다. Date () constructor.

new Date( ) 
new Date(milliseconds) 
new Date(datestring) 
new Date(year,month,date[,hour,minute,second,millisecond ])

Note − 괄호 안의 매개 변수는 항상 선택 사항입니다.

날짜 속성

다음은 설명과 함께 Date 개체의 속성 목록입니다.

Sr. 아니요 속성 및 설명
1 constructor

Specifies the function that creates an object's prototype

2 prototype

The prototype property allows you to add properties and methods to an object

Date Methods

Following is a list of different date methods along with the description.

Sr.No Method & Description
1 Date()

Returns today's date and time

2 getDate()

Returns the day of the month for the specified date according to the local time

3 getDay()

Returns the day of the week for the specified date according to the local time

4 getFullYear()

Returns the year of the specified date according to the local time

5 getHours()

Returns the hour in the specified date according to the local time

6 getMilliseconds()

Returns the milliseconds in the specified date according to the local time

7 getMinutes()

Returns the minutes in the specified date according to the local time

8 getMonth()

Returns the month in the specified date according to the local time

9 getSeconds()

Returns the seconds in the specified date according to the local time

10 getTime()

Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC

11 getTimezoneOffset()

Returns the time-zone offset in minutes for the current locale

12 getUTCDate()

Returns the day (date) of the month in the specified date according to the universal time

13 getUTCDay()

Returns the day of the week in the specified date according to the universal time

14 getUTCFullYear()

Returns the year in the specified date according to the universal time

15 getutcHours()

Returns the hours in the specified date according to the universal time

16 getUTCMilliseconds()

Returns the milliseconds in the specified date according to the universal time

17 getUTCMinutes()

Returns the minutes in the specified date according to the universal time

18 getUTCMonth()

Returns the month in the specified date according to the universal time

19 getUTCSeconds()

Returns the seconds in the specified date according to the universal time

20 setDate()

Sets the day of the month for a specified date according to the local time

21 setFullYear()

Sets the full year for a specified date according to the local time

22 setHours()

Sets the hours for a specified date according to the local time

23 setMilliseconds()

Sets the milliseconds for a specified date according to the local time

24 setMinutes()

Sets the minutes for a specified date according to the local time

25 setMonth()

Sets the month for a specified date according to the local time

26 setSeconds()

Sets the seconds for a specified date according to the local time

27 setTime()

Sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC

28 setUTCDate()

Sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC

29 setUTCFullYear()

Sets the full year for a specified date according to the universal time

30 setUTCHours()

Sets the hour for a specified date according to the universal time

31 setUTCMilliseconds()

Sets the milliseconds for a specified date according to the universal time

32 setUTCMinutes()

Sets the minutes for a specified date according to the universal time

33 setUTCMonth()

Sets the month for a specified date according to the universal time

34 setUTCSeconds()

Sets the seconds for a specified date according to the universal time

35 todatestring()

Returns the "date" portion of the Date as a human-readable string

36 toLocaleDateString()

Returns the "date" portion of the Date as a string, using the current locale's conventions

37 toLocaleString()

Converts a date to a string, using the current locale's conventions

38 toLocaleTimeString()

Returns the "time" portion of the Date as a string, using the current locale's conventions

39 toString()

Returns a string representing the specified Date object

40 toTimeString()

Returns the "time" portion of the Date as a human-readable string

41 toUTCString()

Converts a date to a string, using the universal time convention

42 valueOf()

Returns the primitive value of a Date object