//2019-03-20
  var date = new Date();//Wed Mar 20 2019 11:46:48 GMT+0800 (中国标准时间)
  var date = new Date().getTime();// 返回的是1970到现在的毫秒数,时间戳   1553053625688
  
  var year = date.getFullYear();//年份 2019
  var month = date.getMonth()+1;//月份  3
  var day = date.getDate(); //天  20
  
//获取当前时间,格式YYYY-MM-DD
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}
//js获取当前日期前后N天的方法:
function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m_ = (dd.getMonth()+1).toString();
    var m = '';
    m_.length >1 ? m =m_ : m ='0'+m_;
    var d_ = dd.getDate().toString();
    var d = '';
    d_.length > 1 ? d=d_ : d='0'+d_;
    return y+"-"+m+"-"+d;
}
//时间转换成时间戳
function TimeChange(par) {
    var par_new = par.replace(/-/g, '/');
    var par_time = new Date(par_new);
    var Time = '';
    if(par == ''){
        Time = 0;
    }else{
        Time = par_time.getTime();
    }
    return Time;
}
//传入年份和月份 获取该年对应月份的天数
 getdaysinmonth(year,month){
  var thisDate = new Date(year,month,0); //当天数为0 js自动处理为上一月的最后一天
  return thisDate.getDate();
}

3_hours
82 声望1 粉丝

« 上一篇
vue