从两种不同的日期方法获取毫秒数

Getting milliseconds from two different methods of date

为什么这两种获取毫秒的方式不同

gigasecond = inputDate => {
  console.log(inputDate)
  console.log(inputDate.getTime())     //1303689600000
  console.log(
    Date.UTC(inputDate.getFullYear(), 
             inputDate.getMonth(),
             inputDate.getDate(),
             inputDate.getHours(), 
             inputDate.getMinutes(),
             inputDate.getSeconds())); //1303709400000
};

gigasecond(new Date(Date.UTC(2011, 3, 25)))

getHours() 方法 returns 指定日期的小时,根据当地时间。请改用 getUTCHours()

gigasecond = inputDate => {
  console.log(inputDate)
  console.log(inputDate.getHours(), inputDate.getUTCHours())
  console.log(inputDate.getTime()) //1303689600000
  console.log(
    Date.UTC(inputDate.getFullYear(),
      inputDate.getUTCMonth(),
      inputDate.getUTCDate(),
      inputDate.getUTCHours(),
      inputDate.getUTCMinutes(),
      inputDate.getUTCSeconds()
    )
  ); //1303709400000
};

gigasecond(new Date(Date.UTC(2011, 3, 25)))