Date 日期时间方法大全

195 阅读1分钟

创建当前的对象实例,不带任何参数 let today = new Date(“可以填时间”) 创建当前时间戳的日期时间对象实例,参数是时间戳

时间戳:

指的是某一个时间距离 1970年1月1日0时0分0秒过去了 多少毫秒值 1秒 = 1000毫秒

可以指定多个时间 顺序为年、月、日、时、分、秒, 其中 年、月、日 是必须的

let timer = new Date(2005+100,4,25,10,20,0)

返回指定时间的方法

  1. Date.getDate() 返回一个月中的某一天
  2. Date.getDay() 返回一周中的某一天
  3. Date.getFullYear() 返回Date对象的年份
  4. Date.getHours() 返回Date对象的小时
  5. Date.getMilliseconds() 返回返回Date对象的毫秒
  6. Date.getMinutes() 返回Date对象的分钟
  7. Date.getMoth() 返回Date对象的月份
  8. Date.getSeconds() 返回Date对象的秒
  9. Date.getTime() 返回Date对象的毫秒