JS Date对象

1.date类

  创建Date对象:var time=new Date()

  (1)get系列:

  getDate() 返回一个月中的某一天;1-31

  getDay() 返回一周中的某一天;0-6

  getFullYear() 返回四位数字的年份;

  getMonth() 返回月份;比实际情况小1;0代表1月;0-11

  getHours() 返回的是当前的小时数;0-23

  getMintues() 返回的是当前的分钟数;0-59

  getSecond() 返回当前的秒数;0-59

  getTime() 返回1970年到现在的毫秒数

  parse()返回指定时间到1970年1月1日的毫秒数:Date.parse("月份 日期,年份")

   (2)set系列:

  setDate() 设置对象中的某一天,参数是number 1-31;

  setFullYear() 设置年份,参数 year必填,month和day可选;

  setHours() 设置小时数,参数 hour必填,其他可选。

  setMinutes() 设置分钟数,参数3个,minutes必填 其他可选

  setSecond() 设置秒,2个参数 second必填。

2.案例分析:从现在到2019元旦的倒计时

  html结构:

  

  JS结构:

  

 

猜你喜欢

转载自www.cnblogs.com/yuanjingjing/p/10114745.html