2020-01-13

js获取日期,年月日,星期

var date = new Date,today = '';
    // 当前年份
    var year = date.getFullYear();
    // 当前月份
    var month=date.getMonth()+1;
    month=month < 10 ? "0"+month : month;
    // 几号
    var todate = date.getDate();
    //星期
    var day = date.getDay();
    var chinese =  ["日", "一", "二", "三", "四", "五", "六"];
    var week = chinese[day];
    console.log(week);
    // 标准格式的年月日
    today = year+'-'+month+'-'+todate;
    console.log(today);//2020-01-13 

你可能感兴趣的:(2020-01-13)