JS获取昨天/今天/今年第一天的方法

talk is cheap,show me the code!

 

//获取昨天
            var day1 = new Date();
            day1.setTime(day1.getTime()-24*60*60*1000);
            var yesterDate = day1.getFullYear()+"/" + (day1.getMonth()+1) + "/" + day1.getDate();

 

 //获取当前日期
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            };
            var currentdate = year + '-' + month + '-' + day;

 

//获取今年第一天
            var date1 = new Date();
            var year1 = date.getFullYear();
            var firstMonth = year1 + '-' + '01' + '-' + '01';

 

posted @ 2019-03-14 15:27  krank  阅读(6466)  评论(0编辑  收藏  举报