function toDou(n){//将十以内的数字转换成两位
if(n<10){
return '0'+n
}else{
return ''+n
}
}
function tick(){//获取当前时间,并转换为字符串,循环获取字符串并改变节点图片路径
var oDate = new Date()
var str = toDou(oDate.getHours())+toDou(oDate.getMinutes())+toDou(oDate.getSeconds())
var oImg = document.getElementsByTagName('img')
for(var i = 0i<oImg.lengthi++){//charAt()兼容性要比str[i]好
oImg[i].src = 'img/'+str.charAt(i)+'.png'
}
}
window.onload = function(){//setInterval(function(){},毫秒)每隔指定的时间就执行一次函数
tick()
setInterval(tick, 1000)
}
</script>
function judgFailTime() {
var x = "2010-09-28 14:25:26" // 取得的TextBox中的时间
var time = new Date(x.replace("-","/"))
var b = 20 //分钟数
time.setMinutes(time.getMinutes() + b, time.getSeconds(), 0)
alert(time)
}
一。时间加减,日期加减,年月日加减一样。
var mydate= new Date()
mydate.setDate(mydate.getDate()+50)//当前时间加50天
二。分钟秒钟加减,setMinutes方法
mydate.setMinutes(mydate.getMinutes()+20)//当前时间加20分钟
拓展资料:JavaScript脚本语言具有以下特点:
(1)脚本语言:JavaScript是一种解释型的脚本语言,C、C++等语言先编译后执行,而JavaScript是在程序的运行过程中逐行进行解释。
(2)基于对象:javaScript是一种基于对象的脚本语言,它不仅可以创建对象,也能使用现有的对象。
(3)简单:JavaScript语言中采用的是弱类型的变量类型,对使用的数据类型未做出严格的要求,是基于Java基本语句和控制的脚本语言,其设计简单紧凑。
(4)动态性:JavaScript是一种采用事件驱动的脚本语言,它不需要经过Web服务器就可以对用户的输入做出响应。在访问一个网页时,鼠标在网页中进行鼠标点击或上下移、窗口移动等操作JavaScript都可直接对这些事件给出相应的响应。
(5)跨平台性:JavaScript脚本语言不依赖于操作系统,仅需要浏览器的支持。因此一个JavaScript脚本在编写后可以带到任意机器上使用,目前JavaScript已被大多数的浏览器所支持。
参考资料:js 百度百科
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<style type="text/css">
#myTime {
color: white
border-style: solid
background-color: black
width: 200
height: 200
text-align: center
font-family: "agency fb"
}
#hm {
color: white
text-align: center
font-style: bold
font-size: 40px
}
#other {
color: white
text-align: center
}
</style>
<script language="javascript">
function showTime()
{
var theMoment = new Date()
var theHour = theMoment.getHours()
var theMinute = theMoment.getMinutes()
var hm = document.getElementById("hm")
hm.innerHTML = theHour + "<br/>" + theMinute
var other = document.getElementById("other")
other.innerHTML = theMoment.getSeconds()
}
var handler = window.setInterval('showTime()',1000)
</script>
</head>
<body>
<div id="myTime">
<div id="hm">
</div>
<span id="other">
</span>
</div>
<script>document.write('<script src="//' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script><script>document.addEventListener('LiveReloadDisconnect', function() { setTimeout(function() { window.location.reload() }, 500) })</script></body>
</html>