首页 > 求一个能获取当前实时时间的js

求一个能获取当前实时时间的js

格式是这样的,想要在input里面获取实时时间就好!万分感谢


http://blog.csdn.net/jl244981288/article/details/45649439看看


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 clock = year + "";
if(month < 10)
clock += "0";
clock += month + "";
if(day < 10)
clock += "0";
clock += day ;
return(clock);
}


直接用原生的api就行~

var temp = new Date();
var regex = /\//g;
(temp.toLocaleDateString() + ' ' + temp.toLocaleTimeString().slice(2)).replace(regex,'-');

// "2015-5-7 9:04:10"

time : <input type="text" id="time">


<script type="text/javascript">

var temp = new Date();
var regex = /\//g;
var result = (temp.toLocaleDateString() + ' ' + temp.toLocaleTimeString().slice(2)).replace(regex,'-');
var time = document.getElementById('time').value = result ;

</script>

setInterval(function(){
    var temp = new Date();
    var regex = /\//g;
    var result = (temp.toLocaleDateString() + ' ' + temp.toLocaleTimeString().slice(2)).replace(regex,'-');
    var time = document.getElementById('time').value = result ;
},1000);
【热门文章】
【热门文章】