一、在js中String类型转成date格式

var date = new Date("2018-9-21 14:58:43");//就是这么简单

 

二、date转String类型就有点麻烦了

  var date = new Date();//获取当前日期时间

  var year = date.getFullYear();//
  var month = date.getMonth();//
  var day = date.getDate();//
  var hours = date.getHours();//
  var min = date.getMinutes();//
  var second = date.getSeconds();//

 

 

  

三、求日期差

  1、上面那些直接获取的年月日时分秒都是number类型,直接拿来求差就行了

  2、可以用毫秒值来求差

      var date1 = new Date();//获取当前日期时间
      var date2 = new Date();//获取当前日期时间
      var num = date2.getTime() - date1.getTime();
      num = num /1000/60/60/24;//这是换算天数,求时分秒什么的,依次减少一个来除便行 了

 

相关文章:

  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-05-17
猜你喜欢
  • 2022-12-23
  • 2021-11-27
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
相关资源
相似解决方案