JavaScript 日期

创造 date 函数

  1. new Date()
    1. 当前日期和时间创建先的日期对象
  2. new Date( year,month,day,hours,minutes,seconds,milliseconds)
    1. 指定日期和时间创建先的日期对象
    2. 月份从 0-11
    3. 6 -2 个参数
      1. 6个参数:全部包含、
      2. 5 个参数:年月日小时和分钟、
      3. 四个参数:年月日小时,
      4. 如果只提供一个参数,将其视为毫秒
    4. year 这个参数如果是一位或 2 位,默认是 1900 年开头
  3. new Date(milliseconds)
    1. 创建一个临 时加毫秒的新日期对象
    2. 可以为负数,则表 示 1970 年以前的日期
  4. new Date(date string)
    1. 日期字符串创建一个新的日期对象

      显示日期

      JavaScript 默认可以将全文本字符以字符串格式输出文本
  • toUTCString()
    • 将日期装换为 UTC 字符串
  • toDateString()
    • 将日期转化为更为易读的格式

日期获取方法

  • getDate()
  • getDay()
  • getFullYear()
  • getHours()
  • getMilliseconds()
  • getMinutes()
  • getMonth()
  • getSeconds()
  • getTime()

日期设置方法

  • setDate()
  • setFullYear()
  • setHours()
  • setMilliseconds()
  • setMinutes()
  • setMonth()
  • setSeconds()
  • setTime()