【学习】js获取前一天的日期

<script language="javascript" type="text/javascript">
        function GetDay()
        {
            var   today=new   Date();  
            var   yesterday_milliseconds=today.getTime()-1000*60*60*24;  
            var   yesterday=new   Date();  
            yesterday.setTime(yesterday_milliseconds);  
           
            var strYear=yesterday.getFullYear();
            var strDay=yesterday.getDate();
            var strMonth=yesterday.getMonth()+1;
            if(strMonth<10)
            {
                strMonth="0"+strMonth;
            }
            var strYesterday=strYear+"-"+strMonth+"-"+strDay;
            alert(strYesterday);


            //关闭页面,无提示

            window.opener=null   
            window.open("","_self")   
            window.close();
        }
        GetDay();
    </script>

你可能感兴趣的:(JavaScript,Date,function,null)