I encountered some problems when dealing with date parameters in JS in the morning, and I didn’t know how to add or subtract the time.
The initial idea was to take out year, month, day, hour, minute, second separately, and then add it manually. . . At first I just wanted to just borrow a placement, but later I thought, it was not that easy.
Finally, after a morning of exploration, it was finally done.
First, how to display a standard date and time format "yyyy-mm-dd hh:MM:ss". The temporary approach is to first
var dtNow=new Date(). //Current time
The standard date and time are spelled out, dtNow.getFullYear(), dtNow.getMonth() + 1), dtNow.getDate(), dtNow.toTimeString().split(" ",1)[0] is the information that this standard time string needs to contain.
There is also the method of adding or subtracting time. For example, add N days to the current dtNow
var dtNew=new Date(dtNow.getTime()+N*24*60*60*1000);
Then use dtNew.getFullYear(), etc. to get date, time and other data.
I also want to overload the toString method when writing this, because the original toString returns a bit rich...but the format is not good.
The above brief discussion on the addition and subtraction time in JavaScript is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.