js 获取日期不足两位补 0


<script>
    function appendZero(obj) {
        if(obj<10) return "0" +""+ obj;
        else return obj;
    }
    function getWeek(weeknum) {
        if(weeknum==0)  week="周日";
        if(weeknum==1)  week="周一";
        if(weeknum==2)  week="周二";
        if(weeknum==3)  week="周三";
        if(weeknum==4)  week="周四";
        if(weeknum==5)  week="周五";
        if(weeknum==6)  week="周六";
        return week;
    }
    function getDateWeek() {
        var now=new Date();
        var year=now.getFullYear();
        var month=now.getMonth()+1;
        var date=now.getDate();
        var weeknum=now.getDay();
 
        var s=year + "-"+ appendZero(month) + "-" + appendZero(date) + " " + getWeek(weeknum)+" ";
        document.write(s);
    }
    getDateWeek();
</script>

 

没有更多推荐了,返回首页