请问如何在javascript中获得系统当前日期及时间?

franci007 2001-07-22 04:57:55
如下不行:
<script language="javascript">
function load(){
day=new date();
f1.txt1.value=day.getdate();
</script>
.
.
.
<form name=f1>
<input type=text name=txt1 value="">
</form>
...全文
202 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sdly 2001-07-22
javascript 识别大小写
回复
tripofdream 2001-07-22
http://www.csdn.net/expert/topic/199/199709.shtm
回复
freezwy 2001-07-22
应该是:
var daynow=day.getdate();
document.f1.txt1.value= daynow;]
给你个我用的时间函数,自己修改。
<script language=javascript>
var tTick;
function date() {
var enabled = 0; today = new Date();
var day; var date;
if(today.getDay()==0) day = "星期日"
else if(today.getDay()==1) day = "星期一"
else if(today.getDay()==2) day = "星期二"
else if(today.getDay()==3) day = "星期三"
else if(today.getDay()==4) day = "星期四"
else if(today.getDay()==5) day = "星期五"
else if(today.getDay()==6) day = "星期六";
if (today.getYear()>=2000)
date1 = (today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日 ";
else
date1 = (1900 + today.getYear()) + "年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日 ";
return date1+day;
}

function tick() {
var hours, minutes, seconds, ap;
var intHours, intMinutes, intSeconds;
var today;

today = new Date();

intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();

if (intHours == 0) {
hours = "12:";
ap = "AM";
} else if (intHours < 12) {
hours = intHours+":";
ap = "AM";
} else if (intHours == 12) {
hours = "12:";
ap = "PM";
} else {
intHours = intHours - 12
hours = intHours + ":";
ap = "PM";
}

if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}

if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}

timeString = hours+minutes+seconds+ap;

timeString = "<font color='red'>"+"<center>"+date()+" "+timeString+"</center>"+"</font>";
Clock.innerHTML = timeString

tTick=window.setTimeout("tick();", 1000)
}

document.writeln("<div id=Clock> </div>")
window.onload = tick
window.onunload = new Function("clearTimeout(tTick)")
</script>
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2001-07-22 04:57
社区公告
暂无公告