js苹果系统获取时间戳

 
苹果系统需要 new Date("2019/01/01 00:00:00").getTime();
事件格式需要是 2019/01/01 00:00:00
 
下面的方法判断两个时间差,为秒 ,如果为分的话,把除以1000换成除以1000*60,依次类推
  function datedifference(sDate1, sDate2) {  //苹果系统需要 new Date("2019/01/01 00:00:00").getTime()
    var time1 = new Date(sDate1).getTime(); //sDate1和sDate2是2019/01/01 00:00:00格式

var time2 = new Date(sDate2).getTime();

    var dateSpan = Math.abs(time2 - time1);
    var s= Math.floor(dateSpan / 1000);
    return s;
  };

  

获取当前时间

function pad2(n) { return n < 10 ? '0' + n : n }
 
function getNowFormatDate() {
    var date = new Date();
    const year = date.getFullYear().toString();
    const month = pad2(date.getMonth() + 1);
    const day = pad2(date.getDate());
    const hour = pad2(date.getHours());
    const minute = pad2(date.getMinutes());
    const seconds = pad2(date.getSeconds());

    return `${year}/${month}/${day} ${hour}:${minute}:${seconds}`;
}

  

 
原文地址:https://www.cnblogs.com/ZhiXing-Blogs/p/15529223.html