js,昨天的日期

var mydate = new Date();
        var yester = mydate-24*60*60*1000;
        var yesterday = new Date();
        yesterday.setTime(yester);
                   var str = "" + yesterday.getFullYear() + "-";
                       if (yesterday.getMonth()>=9) {
                           str+=(yesterday.getMonth()+1) + "-";
                       } else{
str
+="0"+(yesterday.getMonth()+1)+"-"; } if ((yesterday.getDate())<10) { str+="0"+(yesterday.getDate()); } else{ str += (yesterday.getDate()); } $("#mydata").val(str);

 

posted @ 2017-11-10 14:03  王怀霞  阅读(194)  评论(0编辑  收藏  举报