js获取系统时间
2017-04-25 17:24:10 来源: 浏览: 次
导读:vardate=newDate();varyear=date getFullYear();varmonth=date getMonth()+1;varday=date getDate();varhour=date getHours();varminute=da
<script type="text/javascript">
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
alert(year+'年'+month+'月'+day+'日 '+hour+':'+minute+':'+second)
$("#time").text(t);
</script>
<div class="time"></div>
下面是动态时间
<script type="text/javascript">
function current(){
var d=new Date(),str='';
str +=d.getFullYear()+'年'; //获取当前年份
str +=d.getMonth()+1+'月'; //获取当前月份(0——11)
str +=d.getDate()+'日';
str +=d.getHours()+'时';
str +=d.getMinutes()+'分';
str +=d.getSeconds()+'秒';
return str; }
setInterval(function(){$("#nowTime").html(current)},1000);
</script>
function current(){
var d=new Date(),str='';
str +=d.getFullYear()+'年'; //获取当前年份
str +=d.getMonth()+1+'月'; //获取当前月份(0——11)
str +=d.getDate()+'日';
str +=d.getHours()+'时';
str +=d.getMinutes()+'分';
str +=d.getSeconds()+'秒';
return str; }
setInterval(function(){$("#nowTime").html(current)},1000);
</script>
<div id="nowTime"></div>