html网页代码中的时间样式怎么设置

<html>
<head>
<title>计算几天后的日期</title>
</head>
<body>
<center><font color=red face="隶书" size=6>提取当前日期</font></center>
<center>
<script language="JavaScript">
<!--
function AddDays(form) {
DaysToAdd=document.form.DaysToAdd.value;
var now=new Date();
var newdate=new Date();
var newtimems=newdate.getTime()+(DaysToAdd*24*60*60*1000);
newdate.setTime(newtimems);
document.form.display.value=newdate.toLocaleString();
}
-->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!--
function goHist(a)
{
history.go(a);
}
-->
</script>
<form name=form>
<input type="hidden" type=text name=DaysToAdd size=4 value=0 onFocus="this.select()" onMouseOver="this.focus()">
<input type=text name="display" size=20 value="">
<input type=button value="提取当前时间" onClick="AddDays(this.form)" name="button">
</form>
</center>
</body>
</html>

提取的时间样式是:2015/6/23 下午6:12:51(这个不好看)
我想要的样式是:2015年06月23日 18:13:51
或者是:2015-06-23 18:13:51

第1个回答  2015-06-24
<form name=form>
<input type="hidden" type=text name=DaysToAdd size=4 value=0 onFocus="this.select()" onMouseOver="this.focus()">
<input type=text name="display" size=20 value="">
<input type=button value="提取当前时间" onClick="AddDays(this.form)" name="button"><script language="JavaScript">
<!--
function CurentTime()
{
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var ss = now.getSeconds(); //秒
var clock = year + "-";
if(month < 10)
clock += "0";
clock += month + "-";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm + ":";
if (ss < 10) clock += '0';
clock += ss;
return(clock);
}
function AddDays(form) {
document.form.display.value=CurentTime();}
-->
</script>本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网