- 浏览: 798001 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (573)
- Java基础 (76)
- C++基础 (5)
- hibernate (5)
- struts (4)
- spring (1)
- webservice (7)
- AjaX基础 (0)
- JS脚本 (53)
- 正则表达式 (5)
- html脚本 (30)
- 数据库基础 (54)
- 工作相关 (49)
- 其他 (30)
- Linux (9)
- web服务器 (17)
- JSP (13)
- eclipse (6)
- 面试题相关 (20)
- XML (3)
- Apache common (2)
- 生活 (35)
- VMware (1)
- log4j (9)
- BeanUtils (2)
- 设计模式 (3)
- UML (1)
- UNIX (1)
- ibats (5)
- GT-Grid (17)
- ABAP学习 (17)
- ABAP (35)
- ABAP--ALV (11)
- ABAP--WEBDIMPRO (0)
- abap-sample (1)
- BEMS (2)
- flex (33)
- GIS技术 (3)
最新评论
时间对象用来操作日期和时间。
Examples
举例
Return today's date and time
使用Date()方法得到今天的日期
getTime()
用getTime()来计算1970年到现在之间的时间差距
setFullYear()
使用getFullYear()来设置指定的日期
toUTCString()
使用UTCString()来将今天的日期转换成字符串(依据UTC)
getDay()
使用getDay()和一数组来书写星期几,并不是简单的数字
Display a clock
怎样在你的页上显示一个时钟
--------------------------------------------------------------------------------
Defining Dates
定义日期
时间对象用来操作日期跟时间
我们通过一个新的关键字来定义一个时间对象。下面的代码行就定义了一个时间对象(称作myDate):
var myDate=new Date()
Note:
注意:时间对象将自动把当前的日期和时间作为初始值!
--------------------------------------------------------------------------------
Manipulate Dates
操作(设置)时间
我们可以轻易地用有效的时间对象来操作(设置)日期或时间
在下面的例子中我们设置一个时间对象来指定日期(2010年一月14号):
var myDate=new Date()myDate.setFullYear(2010,0,14)
下面的例子我们将一时间对象设置为未来的5天:
var myDate=new Date()myDate.setDate(myDate.getDate()+5)
Note:
注意:如果给一日期增加天改为给月或年增加的话,一些变化会由时间对象自动处理!
--------------------------------------------------------------------------------
Comparing Dates
比较时间(日期)
时间对象同样使用在比较两个日期(时间)
下面的例子将今天的日期和2010年1月14号作比较:
var myDate=new Date()myDate.setFullYear(2010,0,14)var today = new Date()if (myDate>today) alert("Today is before 14th January 2010")else alert("Today is after 14th January 2010")
--------------------------------------------------------------------------------
Complete Date Object Reference
完整的时间对象参考
For a complete reference of all the properties and methods that can be used with the Date object, go to our complete Date object reference.
Date[日期]对象中的所有属性和方法参数,我们将在完整Date对象参数 中罗列说明。
The reference contains a brief description and examples of use for each property and method!
我们将列举简要说明和典型案例来讲解每个参数的属性和方法的用法。
Date Object Methods
日期对象方法
FF: Firefox, N: Netscape, IE: Internet Explorer
FF:火狐,N:网景,IE
Method
方法 Description
描述 FF N IE
Date() Returns today's date and time
返回今天的日期和时间 1 2 3
getDate() Returns the day of the month from a Date object (from 1-31)
返回月中的第几天(1到31) 1 2 3
getDay() Returns the day of the week from a Date object (from 0-6)
返回一周中的第几天(0到6) 1 2 3
getMonth() Returns the month from a Date object (from 0-11)
返回月份数(0到11) 1 2 3
getFullYear() Returns the year, as a four-digit number, from a Date object
返回完整的年份数 1 4 4
getYear() Returns the year, as a two-digit or a four-digit number, from a Date object. Use getFullYear() instead !!
返回年份,可以是两位的或是四位的 1 2 3
getHours() Returns the hour of a Date object (from 0-23)
返回日期对象的小时数(0到23) 1 2 3
getMinutes() Returns the minutes of a Date object (from 0-59)
返回日期对象的分钟(0到59) 1 2 3
getSeconds() Returns the seconds of a Date object (from 0-59)
返回日期对象的秒(0到59) 1 2 3
getMilliseconds() Returns the milliseconds of a Date object (from 0-999)
返回毫秒(0到999) 1 4 4
getTime() Returns the number of milliseconds since midnight Jan 1, 1970
从1970年1月1号午夜到现在一共花去的毫秒数 1 2 3
getTimezoneOffset() Returns the difference in minutes between local time and Greenwich Mean Time (GMT)
本地时间和GMT相差多少分钟 1 2 3
getUTCDate() Returns the day of the month from a Date object according to universal time (from 1-31)
依据国际时间来得到月中的第几天(1到31) 1 4 4
getUTCDay() Returns the day of the week from a Date object according to universal time (from 0-6)
依据国际时间来得到现在是星期几(0到6) 1 4 4
getUTCMonth() Returns the month from a Date object according to universal time (from 0-11)
依据国际时间来得到月份(0到11) 1 4 4
getUTCFullYear() Returns the four-digit year from a Date object according to universal time
依据国际时间来得到完整的年份 1 4 4
getUTCHours() Returns the hour of a Date object according to universal time (from 0-23)
依据国际时间来得到小时(0-23) 1 4 4
getUTCMinutes() Returns the minutes of a Date object according to universal time (from 0-59)
依据国际时间来返回分钟(0到59) 1 4 4
getUTCSeconds() Returns the seconds of a Date object according to universal time (from 0-59)
依据国际时间来返回秒(0到59) 1 4 4
getUTCMilliseconds() Returns the milliseconds of a Date object according to universal time (from 0-999)
依据国际时间来返回毫秒(0到999) 1 4 4
parse() Takes a date string and returns the number of milliseconds since midnight of January 1, 1970
或得并返回自1970年1月1号凌晨到现在一共花掉了多少毫秒 1 2 3
setDate() Sets the day of the month in a Date object (from 1-31)
设置日 1 2 3
setMonth() Sets the month in a Date object (from 0-11)
设置月 1 2 3
setFullYear() Sets the year in a Date object (four digits)
设置年份 1 4 4
setYear() Sets the year in the Date object (two or four digits). Use setFullYear() instead !!
用setFullYear()来取代 1 2 3
setHours() Sets the hour in a Date object (from 0-23)
设置小时 1 2 3
setMinutes() Set the minutes in a Date object (from 0-59)
设置分钟 1 2 3
setSeconds() Sets the seconds in a Date object (from 0-59)
设置秒 1 2 3
setMilliseconds() Sets the milliseconds in a Date object (from 0-999)
设置毫秒 1 4 4
setTime() Calculates a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970 1 2 3
setUTCDate() Sets the day of the month in a Date object according to universal time (from 1-31)
依据国际时间来设置日期 1 4 4
setUTCMonth() Sets the month in a Date object according to universal time (from 0-11)
依据国际时间来设置月 1 4 4
setUTCFullYear() Sets the year in a Date object according to universal time (four digits)
依据国际时间来设置年份 1 4 4
setUTCHours() Sets the hour in a Date object according to universal time (from 0-23)
依据国际时间来设置小时 1 4 4
setUTCMinutes() Set the minutes in a Date object according to universal time (from 0-59)
依据国际时间来设置分钟 1 4 4
setUTCSeconds() Set the seconds in a Date object according to universal time (from 0-59)
依据国际时间来设置秒 1 4 4
setUTCMilliseconds() Sets the milliseconds in a Date object according to universal time (from 0-999)
依据国际时间来设置毫秒 1 4 4
toSource() Represents the source code of an object
显示对象的源代码 1 4 -
toString() Converts a Date object to a string
将日期对象转换为字符串 1 2 4
toGMTString() Converts a Date object, according to Greenwich time, to a string. Use toUTCString() instead !!
根据格林威治时间将Date[日期]对象转换为一个字符串。可以使用toUTCString()替代这种方法 1 2 3
toUTCString() Converts a Date object, according to universal time, to a string
根据通用时间将一个Date[日期]对象转换为一个字符串 1 4 4
toLocaleString() Converts a Date object, according to local time, to a string
根据本地时间将一个Date[日期]对象转换为一个字符串 1 2 3
UTC() Takes a date and returns the number of milliseconds since midnight of January 1, 1970 according to universal time
根据通用时间将日期计算为从1970年1月1日午夜至今所经过的时间(单位:毫秒) 1 2 3
valueOf() Returns the primitive value of a Date object
返回日期对象的原始值 1 2 4
--------------------------------------------------------------------------------
Date Object Properties
日期对象属性
Property
属性 Description
描述 FF N IE
constructor A reference to the function that created the object
所建立对象的函数参考 1 4 4
prototype Allows you to add properties and methods to the object
能够为对象加入的属性和方法 1 3 4
Examples
举例
Return today's date and time
使用Date()方法得到今天的日期
getTime()
用getTime()来计算1970年到现在之间的时间差距
setFullYear()
使用getFullYear()来设置指定的日期
toUTCString()
使用UTCString()来将今天的日期转换成字符串(依据UTC)
getDay()
使用getDay()和一数组来书写星期几,并不是简单的数字
Display a clock
怎样在你的页上显示一个时钟
--------------------------------------------------------------------------------
Defining Dates
定义日期
时间对象用来操作日期跟时间
我们通过一个新的关键字来定义一个时间对象。下面的代码行就定义了一个时间对象(称作myDate):
var myDate=new Date()
Note:
注意:时间对象将自动把当前的日期和时间作为初始值!
--------------------------------------------------------------------------------
Manipulate Dates
操作(设置)时间
我们可以轻易地用有效的时间对象来操作(设置)日期或时间
在下面的例子中我们设置一个时间对象来指定日期(2010年一月14号):
var myDate=new Date()myDate.setFullYear(2010,0,14)
下面的例子我们将一时间对象设置为未来的5天:
var myDate=new Date()myDate.setDate(myDate.getDate()+5)
Note:
注意:如果给一日期增加天改为给月或年增加的话,一些变化会由时间对象自动处理!
--------------------------------------------------------------------------------
Comparing Dates
比较时间(日期)
时间对象同样使用在比较两个日期(时间)
下面的例子将今天的日期和2010年1月14号作比较:
var myDate=new Date()myDate.setFullYear(2010,0,14)var today = new Date()if (myDate>today) alert("Today is before 14th January 2010")else alert("Today is after 14th January 2010")
--------------------------------------------------------------------------------
Complete Date Object Reference
完整的时间对象参考
For a complete reference of all the properties and methods that can be used with the Date object, go to our complete Date object reference.
Date[日期]对象中的所有属性和方法参数,我们将在完整Date对象参数 中罗列说明。
The reference contains a brief description and examples of use for each property and method!
我们将列举简要说明和典型案例来讲解每个参数的属性和方法的用法。
Date Object Methods
日期对象方法
FF: Firefox, N: Netscape, IE: Internet Explorer
FF:火狐,N:网景,IE
Method
方法 Description
描述 FF N IE
Date() Returns today's date and time
返回今天的日期和时间 1 2 3
getDate() Returns the day of the month from a Date object (from 1-31)
返回月中的第几天(1到31) 1 2 3
getDay() Returns the day of the week from a Date object (from 0-6)
返回一周中的第几天(0到6) 1 2 3
getMonth() Returns the month from a Date object (from 0-11)
返回月份数(0到11) 1 2 3
getFullYear() Returns the year, as a four-digit number, from a Date object
返回完整的年份数 1 4 4
getYear() Returns the year, as a two-digit or a four-digit number, from a Date object. Use getFullYear() instead !!
返回年份,可以是两位的或是四位的 1 2 3
getHours() Returns the hour of a Date object (from 0-23)
返回日期对象的小时数(0到23) 1 2 3
getMinutes() Returns the minutes of a Date object (from 0-59)
返回日期对象的分钟(0到59) 1 2 3
getSeconds() Returns the seconds of a Date object (from 0-59)
返回日期对象的秒(0到59) 1 2 3
getMilliseconds() Returns the milliseconds of a Date object (from 0-999)
返回毫秒(0到999) 1 4 4
getTime() Returns the number of milliseconds since midnight Jan 1, 1970
从1970年1月1号午夜到现在一共花去的毫秒数 1 2 3
getTimezoneOffset() Returns the difference in minutes between local time and Greenwich Mean Time (GMT)
本地时间和GMT相差多少分钟 1 2 3
getUTCDate() Returns the day of the month from a Date object according to universal time (from 1-31)
依据国际时间来得到月中的第几天(1到31) 1 4 4
getUTCDay() Returns the day of the week from a Date object according to universal time (from 0-6)
依据国际时间来得到现在是星期几(0到6) 1 4 4
getUTCMonth() Returns the month from a Date object according to universal time (from 0-11)
依据国际时间来得到月份(0到11) 1 4 4
getUTCFullYear() Returns the four-digit year from a Date object according to universal time
依据国际时间来得到完整的年份 1 4 4
getUTCHours() Returns the hour of a Date object according to universal time (from 0-23)
依据国际时间来得到小时(0-23) 1 4 4
getUTCMinutes() Returns the minutes of a Date object according to universal time (from 0-59)
依据国际时间来返回分钟(0到59) 1 4 4
getUTCSeconds() Returns the seconds of a Date object according to universal time (from 0-59)
依据国际时间来返回秒(0到59) 1 4 4
getUTCMilliseconds() Returns the milliseconds of a Date object according to universal time (from 0-999)
依据国际时间来返回毫秒(0到999) 1 4 4
parse() Takes a date string and returns the number of milliseconds since midnight of January 1, 1970
或得并返回自1970年1月1号凌晨到现在一共花掉了多少毫秒 1 2 3
setDate() Sets the day of the month in a Date object (from 1-31)
设置日 1 2 3
setMonth() Sets the month in a Date object (from 0-11)
设置月 1 2 3
setFullYear() Sets the year in a Date object (four digits)
设置年份 1 4 4
setYear() Sets the year in the Date object (two or four digits). Use setFullYear() instead !!
用setFullYear()来取代 1 2 3
setHours() Sets the hour in a Date object (from 0-23)
设置小时 1 2 3
setMinutes() Set the minutes in a Date object (from 0-59)
设置分钟 1 2 3
setSeconds() Sets the seconds in a Date object (from 0-59)
设置秒 1 2 3
setMilliseconds() Sets the milliseconds in a Date object (from 0-999)
设置毫秒 1 4 4
setTime() Calculates a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970 1 2 3
setUTCDate() Sets the day of the month in a Date object according to universal time (from 1-31)
依据国际时间来设置日期 1 4 4
setUTCMonth() Sets the month in a Date object according to universal time (from 0-11)
依据国际时间来设置月 1 4 4
setUTCFullYear() Sets the year in a Date object according to universal time (four digits)
依据国际时间来设置年份 1 4 4
setUTCHours() Sets the hour in a Date object according to universal time (from 0-23)
依据国际时间来设置小时 1 4 4
setUTCMinutes() Set the minutes in a Date object according to universal time (from 0-59)
依据国际时间来设置分钟 1 4 4
setUTCSeconds() Set the seconds in a Date object according to universal time (from 0-59)
依据国际时间来设置秒 1 4 4
setUTCMilliseconds() Sets the milliseconds in a Date object according to universal time (from 0-999)
依据国际时间来设置毫秒 1 4 4
toSource() Represents the source code of an object
显示对象的源代码 1 4 -
toString() Converts a Date object to a string
将日期对象转换为字符串 1 2 4
toGMTString() Converts a Date object, according to Greenwich time, to a string. Use toUTCString() instead !!
根据格林威治时间将Date[日期]对象转换为一个字符串。可以使用toUTCString()替代这种方法 1 2 3
toUTCString() Converts a Date object, according to universal time, to a string
根据通用时间将一个Date[日期]对象转换为一个字符串 1 4 4
toLocaleString() Converts a Date object, according to local time, to a string
根据本地时间将一个Date[日期]对象转换为一个字符串 1 2 3
UTC() Takes a date and returns the number of milliseconds since midnight of January 1, 1970 according to universal time
根据通用时间将日期计算为从1970年1月1日午夜至今所经过的时间(单位:毫秒) 1 2 3
valueOf() Returns the primitive value of a Date object
返回日期对象的原始值 1 2 4
--------------------------------------------------------------------------------
Date Object Properties
日期对象属性
Property
属性 Description
描述 FF N IE
constructor A reference to the function that created the object
所建立对象的函数参考 1 4 4
prototype Allows you to add properties and methods to the object
能够为对象加入的属性和方法 1 3 4
发表评论
-
JavaScript事件
2010-05-13 14:37 1304事件(上) JavaScript事件列表 事件 解说 一般 ... -
flex学习
2010-05-06 20:17 837flex学习例子, -
JSON法创建JavaScript对象
2010-01-14 21:33 938<!DOCTYPE html PUBLIC " ... -
JavaScript Math 对象与函数
2010-01-14 21:16 1222Math函数 Math.abs() -- 返回 ... -
JavaScript Date 对象与函数
2010-01-14 21:14 958JavaScript_Date对象说明 Date对象构造函数 ... -
日历控件
2010-01-13 16:03 837日历控件 编辑控件 -
访问iframe里面的javascript函数、对象,兼容IE、Firefox
2009-12-29 23:16 1605假如你当前主页面中嵌入了一个iframe,ID为:iframe ... -
document.createElement等DOM函数与属性
2009-12-18 17:05 12381、创建节点 createElemen ... -
document.createElement("A")的相关属性
2009-12-18 17:03 1979<html> <BODY> ... -
removeChild 使用注意事项
2009-12-18 16:55 904Java代码 var giftBody = document ... -
获取HTML DOM节点元素的方法
2009-12-18 16:47 1126在Web应用程序特别是Web2.0程序开发中,经常要获取页面 ... -
js 按钮交互 元素属性获取
2009-12-18 16:44 1071<html xmlns="http://www ... -
HTML DOM selectedIndex 属性
2009-12-18 16:34 1365定义和用法 selectedIndex 属性可设置或返回下拉 ... -
hyperlink 控制
2009-12-18 16:09 979<html> <head> ... -
onchange()和onblur()
2009-12-18 15:54 1457<html> <head> ... -
js动态显示时间
2009-12-18 15:48 2830<html> <head> ... -
Javascript 操作select控件大全(新增、修改、删除、选中、清空、判断存在等)
2009-12-16 17:40 8361判断select选项中 是否存在Value="pa ... -
javascript 暂定执行一段时间
2009-12-16 17:31 2205有人说window.setTimeout("func ... -
JS常用对象介绍
2009-12-16 17:22 910click() 对象.click() ------------ ... -
JS事件对象
2009-12-16 17:20 1233事件源对象 event.srcElement.tagName ...
评论