fxxqq / 6fedcom.github.io

frank的前端养成记(hexo博客)
https://6fed.com
22 stars 5 forks source link

js计算星期几 #120

Open fxxqq opened 5 years ago

fxxqq commented 5 years ago
    // 日期
    var myDate = new Date();
    var year=myDate.getFullYear();    //获取完整的年份(4位,1970-????)
    var month=myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
    var date=myDate.getDate();        //获取当前日(1-31)
    console.log(year+"-"+month+"-"+date)
    var str = "星期" + "日一二三四五六".charAt(new Date().getDay());
    console.log(str)
    $(".titleRight").text(year+"-"+month+"-"+date+" "+str)
    // 此处引用
    <div class="titleRight f_right">2017-9-25 星期六</div>