Before acquiring the current date by one day js

Use the time stamp obtaining

var date = +new Date(); //获取当前日期时间戳

var before = date-1000*60*60*24;//当前日期时间戳减去一天时间戳

var beforeDate = new Date(before);//将时间戳转化为Date对象

var result = beforeDate.toLocaleString();//当前日期2016/9/1 下午1:17:55 转化为 -->  2016/8/31 下午1:17:55

Use setDate () method

setDate (1 ~ 31) for setting a day of a month, a range between 1 and 31 days.
If it is passed, then 0 target date for the last day of the month,
if you pass a negative number, such as -1, target date for the penultimate day of last month.

var date = new Date();

date.setDate(0);//设置为上个月最后一天

date.toLocaleString();//"2016/8/30 下午1:44:10"

date.getDate();//获取上一天日期

other

Collating my own learning process read books and other books ready to watch, I want to help, the next will continue to update up new books:
JavaScript eBook Collection

Published 25 original articles · won praise 31 · views 110 000 +

Guess you like

Origin blog.csdn.net/qq_33236453/article/details/52398660
Recommended