简体   繁体   中英

basic Time and Date manipulation in JavaScript

I have a time stamp of the in following form

2013-05-05 16:00:00

Can anyone tell me how to get rid of the time part and advance it one day using javascript, so I have.

2013-05-06
var date1 = new Date("2013-05-06 16:00:00");

var date2 = new Date(date1.getFullYear(),date1.getMonth(),date1.getDate()+1)

Ok well make the time stamp a string and use the .split() method on the space that separates the date and time take a look here for more information: http://www.w3schools.com/jsref/jsref_split.asp

Or more appropriately use the requisite date function like new Date(year,month,day); http://www.w3schools.com/jsref/jsref_obj_date.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM