Coffeescript 简明教程
CoffeeScript - Date
Date 对象是 JavaScript 语言中内置的一个数据类型。Date 对象作为 new Date( ) 创建。
The Date object is a data-type built into the JavaScript language. Date objects are created as new Date( ).
创建 Date 对象后, 多个方法允许你对其进行操作。大部分方法仅允许你获取和设置对象的年、月、日、小时、分钟、秒和毫秒字段, 使用本地时间或 UTC (通用或 GMT) 时间。
Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.
ECMAScript 标准要求 Date 对象能表示任意日期和时间, 至毫秒精度, 于 1/1/1970 前后 1 亿天内。这是正负 273,785 年的范围, 因此 JavaScript 可以表示到 275755 年的日期和时间。
The ECMAScript standard requires the Date object to be able to represent any date and time, to millisecond precision, within 100 million days before or after 1/1/1970. This is a range of plus or minus 273,785 years, so JavaScript can represent date and time till the year 275755.
与其他 JavaScript 对象类似,我们还可以在 CoffeeScript 代码中使用 date 对象。
Similar to other JavaScript objects we can also use the date object in our CoffeeScript code.
Date Methods
以下是 JavaScript 的 Date 对象的各个方法的列表。点击这些方法的名称以获取在 CoffeeScript 中演示其用法的示例。
Following is the list of methods of the Date object of JavaScript. Click on the name of these methods to get an example demonstrating their usage in 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. |