- ES6 教程
- ES6 - 主页
- ES6 - 概述
- ES6 - 环境
- ES6 - 语法
- ES6 - 变量
- ES6 - 运算符
- ES6 - 决策
- ES6 - 循环
- ES6 - 函数
- ES6 - 事件
- ES6 - Cookie
- ES6 - 页面重定向
- ES6 - 对话框
- ES6 - 无效关键字
- ES6 - 页面打印
- ES6 - 对象
- ES6 - 数字
- ES6 - 布尔值
- ES6 - 字符串
- ES6 - 符号
- ES6 - 新的字符串方法
- ES6 - 数组
- ES6 - 日期
- ES6 - 数学
- ES6 - 正则表达式
- ES6 - HTML DOM
- ES6 - 迭代器
- ES6 - 集合
- ES6 - 类
- ES6 - 地图和集合
- ES6 - 承诺
- ES6 - 模块
- ES6 - 错误处理
- ES6 - 对象扩展
- ES6 - 反射 API
- ES6 - 代理 API
- ES6 - 验证
- ES6 - 动画
- ES6 - 多媒体
- ES6 - 调试
- ES6 - 图像映射
- ES6 - 浏览器
- ES7 - 新特性
- ES8 - 新特性
- ES9 - 新特性
- ES6 有用资源
- ES6 - 快速指南
- ES6 - 有用的资源
- ES6 - 讨论
ES6 - Date
The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date () as shown in the following syntax.
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.
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.
You can use any of the following syntax to create a Date object using Date () constructor.
new Date( ) new Date(milliseconds) new Date(datestring) new Date(year,month,date[,hour,minute,second,millisecond ])
Note − Parameters in the brackets are always optional.
Date Properties
Here is a list of the properties of the Date object along with their description.
Sr.No | Property & Description |
---|---|
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 |