Date对象用于处理日期和时间
有5种构造形式
(1)new Date("month dd,yyyy hh:mm:ss");
(2)new Date("month dd,yyyy");
(3)new Date(yyyy,mth,dd,hh,mm,ss);
(4)new Date(yyyy,mth,dd);
(5)new Date(ms);
参数的含义:
有5种构造形式
(1)new Date("month dd,yyyy hh:mm:ss");
(2)new Date("month dd,yyyy");
(3)new Date(yyyy,mth,dd,hh,mm,ss);
(4)new Date(yyyy,mth,dd);
(5)new Date(ms);
参数的含义:
- month:用英文表示的月份名称,从January到December
- mth:用整数表示的月份,从0(1月)到11(12月)
- dd:表示一个月中的第几天,从1到31
- yyyy:四位表示的年份
- hh:小时数,从0到23
- mm:分钟数,从0到59的整数
- ss:秒数,从0到59的整数
- ms:毫秒数,为大于等于0的整数
例:
<script language="javascript" type="text/javascript"> </script>new Date("January 12,2006 22:19:35")=Thu Jan 12 22:19:35 UTC+0800 2006
new Date("January 12,2006")=Thu Jan 12 00:00:00 UTC+0800 2006
new Date(2006,1,12,22,19,35)=Sun Feb 12 22:19:35 UTC+0800 2006
new Date(2006,1,12)=Sun Feb 12 00:00:00 UTC+0800 2006
new Date(11370755750000)=Thu Jan 12 22:19:35 UTC+0800 2006
Date对象中的方法方法描述getFullYear() 以四位数字返回年份 getYear() 根据浏览器的不同,以四位或两位数字返回年份 getMonth() 用整数表示的月份,从0(1月)到11(12月) getDate() 返回一个月中的第几天,从1到31 getDay() 返回星期几,从0(星期日)到6(星期六) getHours() 返回小时数,从0到23 getMinutes() 返回分钟数,从0到59的整数 getSeconds() 返回秒数,从0到59的整数 getMilliseconds() 返回秒中的毫秒数,从0到999 getTime() 返回从GMT时间1970年1月1日起经过的毫秒数 setFullYear(yyyy) 设置日期为某一年 setYear(yy) 设置日期为某一年 setMonth(mth) 设置月份,从0(1月)到11(12月) setDate(dd) 设置天数,从1到31 setHours(hh) 设置小时,从0到23 setMinutes(mm) 设置分钟数,从0到59的整数 setSeconds(ss) 设置秒数,从0到59的整数 setMilliseconds(ms) 设置秒中的毫秒数,从0到999 setTime(ms) 设置日期为从GMT时间1970年1月1日起经过的毫秒数 toString() 将Date对象转换为字符串 Date.parse(string) 静态方法,将合法的描述日期的字符串转换为日期对象并返回