日期:2014-05-16 浏览次数:20447 次
function nextDay(dateStr){
var currDate = new Date(dateStr),
currHours = currDate.getHours(),
nextHours = currDate.setHours(currHours + 24),
nextDay = new Date(nextHours);
return nextDay;
}
console.log(nextDay("2014-5-31").toLocaleDateString());
function prevDay(dateStr){
var currDate = new Date(dateStr),
currHours = currDate.getHours(),
prevHours = currDate.setHours(currHours - 24),
prevDay = new Date(prevHours);
return prevDay;
}
console.log(prevDay("2014-5-1").toLocaleDateString());
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0-beta1.js"></script>
</head>
<body>
<script language="javascript">
function goprovday()
{
var oForm = document.forms["form1"];
var objtxt = oForm.saleDateBegin.value;
//获得值写入 saleDateBegin 框内
oForm.saleDateBegin.value = objtxt - 1 ; // 这儿该怎么写呢?
oForm.saleDateEnd.value = objtxt ;
//oForm.submit();
}
function next(){//其他的类推
var objtxt = oForm.saleDateBegin.value;
objtxt = objtxt.replace(/-/g,'/'); // 将-替换成/,因为下面这个构造函数只支持/分隔的日期字符串
var currDate = new Date(objtxt);
&nb