JS中的日期(Date)对象

来源:互联网 发布:mac os lion无法升级 编辑:程序博客网 时间:2024/06/06 11:48

Date 对象方法

FF: Firefox, IE: Internet Explorer

方法 描述 FF IE
Date() 返回当日的日期和时间。 1 3
getDate() 从 Date 对象返回一个月中的某一天 (1 ~ 31)。 1 3
getDay() 从 Date 对象返回一周中的某一天 (0 ~ 6)。 1 3
getMonth() 从 Date 对象返回月份 (0 ~ 11)。 1 3
getFullYear() 从 Date 对象以四位数字返回年份。 1 4
getYear() 请使用 getFullYear() 方法代替。 1 3
getHours() 返回 Date 对象的小时 (0 ~ 23)。 1 3
getMinutes() 返回 Date 对象的分钟 (0 ~ 59)。 1 3
getSeconds() 返回 Date 对象的秒数 (0 ~ 59)。 1 3
getMilliseconds() 返回 Date 对象的毫秒(0 ~ 999)。 1 4
getTime() 返回 1970 年 1 月 1 日至今的毫秒数。 1 3
getTimezoneOffset() 返回本地时间与格林威治标准时间 (GMT) 的分钟差。 1 3
getUTCDate() 根据世界时从 Date 对象返回月中的一天 (1 ~ 31)。 1 4
getUTCDay() 根据世界时从 Date 对象返回周中的一天 (0 ~ 6)。 1 4
getUTCMonth() 根据世界时从 Date 对象返回月份 (0 ~ 11)。 1 4
getUTCFullYear() 根据世界时从 Date 对象返回四位数的年份。 1 4
getUTCHours() 根据世界时返回 Date 对象的小时 (0 ~ 23)。 1 4
getUTCMinutes() 根据世界时返回 Date 对象的分钟 (0 ~ 59)。 1 4
getUTCSeconds() 根据世界时返回 Date 对象的秒钟 (0 ~ 59)。 1 4
getUTCMilliseconds() 根据世界时返回 Date 对象的毫秒(0 ~ 999)。 1 4
parse() 返回1970年1月1日午夜到指定日期(字符串)的毫秒数。 1 3
setDate() 设置 Date 对象中月的某一天 (1 ~ 31)。 1 3
setMonth() 设置 Date 对象中月份 (0 ~ 11)。 1 3
setFullYear() 设置 Date 对象中的年份(四位数字)。 1 4
setYear() 请使用 setFullYear() 方法代替。 1 3
setHours() 设置 Date 对象中的小时 (0 ~ 23)。 1 3
setMinutes() 设置 Date 对象中的分钟 (0 ~ 59)。 1 3
setSeconds() 设置 Date 对象中的秒钟 (0 ~ 59)。 1 3
setMilliseconds() 设置 Date 对象中的毫秒 (0 ~ 999)。 1 4
setTime() 以毫秒设置 Date 对象。 1 3
setUTCDate() 根据世界时设置 Date 对象中月份的一天 (1 ~ 31)。 1 4
setUTCMonth() 根据世界时设置 Date 对象中的月份 (0 ~ 11)。 1 4
setUTCFullYear() 根据世界时设置 Date 对象中的年份(四位数字)。 1 4
setUTCHours() 根据世界时设置 Date 对象中的小时 (0 ~ 23)。 1 4
setUTCMinutes() 根据世界时设置 Date 对象中的分钟 (0 ~ 59)。 1 4
setUTCSeconds() 根据世界时设置 Date 对象中的秒钟 (0 ~ 59)。 1 4
setUTCMilliseconds() 根据世界时设置 Date 对象中的毫秒 (0 ~ 999)。 1 4
toSource() 返回该对象的源代码。 1 -
toString() 把 Date 对象转换为字符串。 1 4
toTimeString() 把 Date 对象的时间部分转换为字符串。 1 4
toDateString() 把 Date 对象的日期部分转换为字符串。 1 4
toGMTString() 请使用 toUTCString() 方法代替。 1 3
toUTCString() 根据世界时,把 Date 对象转换为字符串。 1 4
toLocaleString() 根据本地时间格式,把 Date 对象转换为字符串。 1 3
toLocaleTimeString() 根据本地时间格式,把 Date 对象的时间部分转换为字符串。 1 3
toLocaleDateString() 根据本地时间格式,把 Date 对象的日期部分转换为字符串。 1 3
UTC() 根据世界时返回 1970 年 1 月 1 日 到指定日期的毫秒数。 1 3
valueOf() 返回 Date 对象的原始值。 1 4
JS:1.5.2,获取当前日期

<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script language="javascript">function dateDemo(){    var d,s="今天的日期是:";    //声明变量。    d=new Date();                //创建Date对象。    s +=(d.getMonth()+1)+"/";    //获取月份。    s +=(d.getDate())+"/";        //获取日。    s +=d.getYear();            //获取年份。    return s;    }</script></head><body><h1>Date对象</h1><pre>function dateDemo(){    var d,s="今天的日期是:";    //声明变量。    d=new Date();                //创建Date对象。    s +=(d.getMonth()+1)+"/";    //获取月份。    s +=(d.getDate())+"/";        //获取日。    s +=d.getYear();            //获取年份。    return s;    }</pre><script language="javascript">document.write(dateDemo());</script></body></html>

Date对象

function dateDemo(){    var d,s="今天的日期是:";  //声明变量。    d=new Date();               //创建Date对象。    s +=(d.getMonth()+1)+"/";   //获取月份。    s +=(d.getDate())+"/";      //获取日。    s +=d.getYear();            //获取年份。    return s;   }

JS:1.5.3,动态时钟

<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script language="javascript">function dispTime(){    var time=new Date();        //获取当前时间。    var hour=time.getHours();    //获取小时,分钟,秒。    var minute=time.getMinutes();    var second=time.getSeconds();    var apm="AM";    //默认显示上午:AM。    if(hour>12)    {        //按照12小时制止显示        hour=hour-12;        apm="PM";    }    if(minute<10)    {        //如果分钟只有1位,补0显示        minute="0"+minute;    }    if(second<10)    //如果秒数只有1位,补0显示    {        second="0"+second;    }    //document.myform.myclock.value=hour+":"+minute+":"+second+":"+apm;    document.getElementById("myclock").innerText=hour+":"+minute+":"+second+":"+apm;}</script></head><body onload="setInterval('dispTime()',1000)"><h1>动态时间</h1><form id="myform"><span id="myclock"></span></form></span></body></html>

warn 作者:ylbtech
出处:http://ylbtech.cnblogs.com/

0 0
原创粉丝点击