📜  CoffeeScript-日期

📅  最后修改于: 2020-10-26 05:49:20             🧑  作者: Mango


Date对象是JavaScript语言中内置的一种数据类型。日期对象被创建为新的Date()

创建Date对象后,可以使用多种方法对其进行操作。大多数方法仅允许您使用本地时间或UTC(通用或GMT)时间来获取和设置对象的年,月,日,时,分,秒和毫秒字段。

ECMAScript标准要求Date对象必须能够在1970年1月1日之前或之后的1亿天内以毫秒为单位表示任何日期和时间。范围是正负273,785年,因此JavaScript可以表示直到275755年的日期和时间。

与其他JavaScript对象类似,我们也可以在CoffeeScript代码中使用date对象。

日期方法

以下是JavaScript的Date对象的方法列表。单击这些方法的名称,以获取示例说明在CoffeeScript中的用法。

S.No. Method & Description
1 getDate()

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

2 getDay()

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

3 getFullYear()

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

4 getHours()

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

5 getMilliseconds()

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

6 getMinutes()

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

7 getMonth()

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

8 getSeconds()

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

9 getTime()

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

10 getTimezoneOffset()

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

11 getUTCDate()

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

12 getUTCDay()

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

13 getUTCFullYear()

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

14 getUTCHours()

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

15 getUTCMinutes()

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

16 getUTCMilliseconds()

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

17 getUTCMonth()

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

18 getUTCSeconds()

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

19 getYear()

Deprecated – Returns the year in the specified date according to local time. Use getFullYear instead.

20 setDate()

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

21 setFullYear()

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

22 setHours()

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

23 setMilliseconds()

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

24 setMinutes()

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

25 setMonth()

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

26 setSeconds()

Sets the seconds for a specified date according to 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 day of the month for a specified date according to universal time.

29 setUTCFullYear()

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

30 setUTCHours()

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

31 setUTCMilliseconds()

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

32 setUTCMinutes()

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

33 setUTCMonth()

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

34 setUTCSeconds()

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

35 setYear()

Deprecated – Sets the year for a specified date according to local time. Use setFullYear instead.

36 toDateString()

Returns the “date” portion of the Date as a human-readable string.

37 toLocaleDateString()

Returns the “date” portion of the Date as a string, using the current locale’s conventions.

38 toLocaleString()

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

39 toLocaleTimeString()

Returns the “time” portion of the Date as a string, using the current locale’s conventions.

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.