输入一个时间差 (如50 单位小时 )
算出距离现在时间50小时的未来时间。。。
输出最好是这样结果2012-02-08 16:22
------解决方案--------------------
<html>
<head>
<script type="text/javascript">
function GetTimeDistance(time, unit)
{
var dateNow = new Date();
switch(unit){
case 'd':
dateNow.setDate(dateNow.getDate()+parseInt(time));
break;
//...
default:
break;
}
return getDateToStr(dateNow, true);
}
function getDateToStr(date, isDateTime) {
if (isDateTime == null) isDateTime = false;
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var hour = (date.getHours() < 10) ? '0' + date.getHours() : date.getHours();
var minute = (date.getMinutes() < 10) ? '0' + date.getMinutes() : date.getMinutes();
return year + "-" + month + "-" + day + (isDateTime ? (" " + hour + ":" + minute) : "");
}
</script>
</head>
<body>
<input type="text" id="Time">
<input type="button" onclick="alert(GetTimeDistance(document.getElementById('Time').value, 'd'))">
</body>
</html>