JavaScript的日期Date对象

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);
参数的含义:
  • 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)静态方法,将合法的描述日期的字符串转换为日期对象并返回
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值