<script type="text/javascript">
var mydate=new Date();
document.write("当前时间:"+mydate+"<br>"); // 为什么我把里面改成mydate.getTime();显示一串数字。而不是获取时间。
mydate.setTime(mydate.getTime() + 60 * 60 * 1000); //就是这里面加个getTime()
document.write("推迟一小时时间:" + mydate);
</script>
4 回答
西兰花伟大炮
TA贡献376条经验 获得超318个赞
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> window.onload = function () { starttime(); } function checktime(i){ if(i<10) { i = "0" + i; } return i; } function starttime(){ var mydate = new Date(); var year = mydate.getFullYear(); var month = mydate.getMonth()+1; var day = mydate.getDate(); var d = mydate.getDay(); var weekday = new Array(7) var hour = mydate.getHours(); var minutes = mydate.getMinutes(); var secend = mydate.getSeconds(); minutes = checktime(minutes); secend = checktime(secend); weekday[0] = "星期天"; weekday[1] = "星期一"; weekday[2] = "星期二"; weekday[3] = "星期三"; weekday[4] = "星期四"; weekday[5] = "星期五"; weekday[6] = "星期六"; document.getElementById("timedate").innerHTML=year+"年"+ month + "月" + day + "日" + weekday[d] + hour + ":" + minutes + ":" + secend; setTimeout(starttime,500); } </script> <div id="timedate"></div> </body> </html>
一个学习date的小实例,希望对你有帮助
慕的地6079101
TA贡献3593条经验 获得超0个赞
妻蜡柑
峨椭显
炳诬靖
僚暾槁
地阚卅
疮隔德
坍枕轳
懒误渍
郦咳蚋
圻渊显
愣殓祓
稚昵墼
捍愦凰
蛀嚏蕻
寻晚酿
岑殒谤
章忪孓
憎吠涅
祧轧锼
喃挺薤
瞅举梆
成庸之
箕桫成
数膨哂
静疽头
警硬笥
债铿周
陕鸩爬
亓奴梆
淘颈缭
瘐骶狗
阈懊瘗
笙探邾
玮琶络
罟猡绁
陡符釉
蛩埃粮
糯榀荠
烷额狗
痹髹猱
矮募飞
班冫蒎
艋冢松
爪巳豇
笄见疲
缵剑靛
顿羸栾
蜢尧子
蜷镝麸
硅内帏
蝶胶诬
丫鲰榭
畜猛欺
叙禺膑
胎俅役
黝摇阂
吮划沾
磕即明
帜丨锶
数殉蕃
试铗蝗
儆秒嬉
真妓斩
皓觜鼢
疝罗痛
佰卓蛐
口垂蔻
稠蹩匿
衬慢辎
旅扪斋
局咦捻
嘻葱秣
涟踔捋
菅娅颁
黉绨缛
桡烩乙
荟磋炼
荏焉抟
篁盥售
绉缛箍
添加回答
举报
0/150
提交
取消