Js时间差计算 博客分类: Js javascript
程序员文章站
2024-02-18 20:05:40
...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js时间计算</title>
<script language="javascript" type="text/javascript">
<!--
function startToEndDate(){
var end_date = new Date();
var start_date = new Date();
start_date.setTime(end_date.getTime()-24*60*60*1000);
var start_year = start_date.getFullYear();
//getMonth中,以0为基数计算
var start_month = addZero(start_date.getMonth()+1);
var start_days = addZero(start_date.getDate());
var end_years = end_date.getFullYear();
var end_month = addZero(end_date.getMonth()+1);
var end_days = addZero(end_date.getDate());
var hours = addZero(end_date.getHours());
var minutes = addZero(end_date.getMinutes());
var seconds=addZero(end_date.getSeconds());
startDate = start_year+'-'+start_month+'-'+start_days+' '+hours+':'+minutes+':'+seconds;
endDate = end_years+'-'+end_month+'-'+end_days+' '+hours+':'+minutes+':'+seconds;
document.write("<h2>"+"startDate:"+startDate+",endDate:"+endDate+"</h2>");
}
function addZero(temp){
if(temp<10) return "0"+temp;
else return temp;
}
//-->
</script>
</head>
<body>
<script language="javascript" type="text/javascript">
startToEndDate();
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js时间计算</title>
<script language="javascript" type="text/javascript">
<!--
function startToEndDate(){
var end_date = new Date();
var start_date = new Date();
start_date.setTime(end_date.getTime()-24*60*60*1000);
var start_year = start_date.getFullYear();
//getMonth中,以0为基数计算
var start_month = addZero(start_date.getMonth()+1);
var start_days = addZero(start_date.getDate());
var end_years = end_date.getFullYear();
var end_month = addZero(end_date.getMonth()+1);
var end_days = addZero(end_date.getDate());
var hours = addZero(end_date.getHours());
var minutes = addZero(end_date.getMinutes());
var seconds=addZero(end_date.getSeconds());
startDate = start_year+'-'+start_month+'-'+start_days+' '+hours+':'+minutes+':'+seconds;
endDate = end_years+'-'+end_month+'-'+end_days+' '+hours+':'+minutes+':'+seconds;
document.write("<h2>"+"startDate:"+startDate+",endDate:"+endDate+"</h2>");
}
function addZero(temp){
if(temp<10) return "0"+temp;
else return temp;
}
//-->
</script>
</head>
<body>
<script language="javascript" type="text/javascript">
startToEndDate();
</script>
</body>
</html>
推荐阅读
-
Js时间差计算 博客分类: Js javascript
-
Extjs3综合应用(待续v4...初版) 博客分类: js EXTSpringJSPStrutsiBATIS 最近又要搞界面了。郁闷啊。
-
extjs json解析List数据 博客分类: js jsonEXTStrutsXML
-
EXTJS 中Ajax 应用示例 博客分类: js Ajax网络应用应用服务器EXTjson
-
Js时间差计算 博客分类: Js javascript
-
extjs 复选框处理 博客分类: js EXTFirebug
-
EXTJS3 简易下拉框 easyCombo 博客分类: js
-
extjs two tree 动态双树代码 效果图 博客分类: js EXTJSP
-
jquery 的苦脑 博客分类: js jQuery
-
js字符串的操作(分割) 博客分类: JS Notes