baozhengrui

导航

将 几个小时前、分钟前、秒前、转换成年月日 时分秒

将 几个小时前、分钟前、秒前、转换成年月日 时分秒

几秒前:minuteTemp / 60;
20分钟前:minuteTemp;
几小时前: minuteTemp * 60;
几天前: minuteTemp * 60 * 60;
几星期钱: minuteTemp * 60 * 60 * 7;
几月前:minuteTemp * 60 * 60 * 30;
几年前: minuteTemp * 60 * 60 * 30 * 365;
 console.log('dddd',getNowFormatDate(20*60));
  function getNowFormatDate(minuteTemp) {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    //前十分钟时间
    var minutes=parseInt(minuteTemp);

    var interTimes=minutes*60*1000;

    var interTimes=parseInt(interTimes);
    date=new   Date(Date.parse(date)-interTimes);

    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hour = date.getHours();
    var minutes = date.getMinutes();
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    if (hour >= 0 && hour <= 9) {
      hour = "0" + hour;
    }
    if (minutes >= 0 && minutes <= 9) {
      minutes = "0" + minutes;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
      + " " + hour + seperator2 + minutes
      + seperator2 + date.getSeconds();
    return currentdate;
  }

posted on 2023-03-30 11:36  芮艺  阅读(222)  评论(0编辑  收藏  举报