简体   繁体   English

JavaScript中的基本时间和日期操作

[英]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. 谁能告诉我如何摆脱时间部分,并使用javascript将其提前一天,所以我有。

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 好的,将时间戳记.split()字符串,并在分隔日期和时间的空格上使用.split()方法,请在此处查看更多信息: http : //www.w3schools.com/jsref/jsref_split.asp

Or more appropriately use the requisite date function like new Date(year,month,day); 或者更适当地使用必要的日期函数,例如new Date(year,month,day); http://www.w3schools.com/jsref/jsref_obj_date.asp http://www.w3schools.com/jsref/jsref_obj_date.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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