JavaScript 实现获取当前时间
2018-04-09 11:49
513 查看
<script language="javascript"
type="text/javascript">
<!--
function tick() {
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var today, theday;
today = new Date();
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六");
theday = today.getYear()+"年" + [today.getMonth()+1]+"月"
+today.getDate() +" "+ d[today.getDay()+1];
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();
if (intHours == 0) {
hours = "12:";
xfile = "午夜";
} else if (intHours < 12) {
hours = intHours+":";
xfile = "上午";
} else if (intHours == 12) {
hours = "12:";
xfile = "正午";
} else {
intHours = intHours - 12
hours = intHours + ":";
xfile = "下午";
}
if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}
if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}
timeString = theday+" "+xfile+" "+hours+minutes+seconds;
Clock.innerHTML = timeString;
window.setTimeout("tick();", 100);
}
window.onload = tick;
-->
</script>
<div
id="Clock"></div>
<!--输出-->
type="text/javascript">
<!--
function tick() {
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var today, theday;
today = new Date();
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六");
theday = today.getYear()+"年" + [today.getMonth()+1]+"月"
+today.getDate() +" "+ d[today.getDay()+1];
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();
if (intHours == 0) {
hours = "12:";
xfile = "午夜";
} else if (intHours < 12) {
hours = intHours+":";
xfile = "上午";
} else if (intHours == 12) {
hours = "12:";
xfile = "正午";
} else {
intHours = intHours - 12
hours = intHours + ":";
xfile = "下午";
}
if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}
if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}
timeString = theday+" "+xfile+" "+hours+minutes+seconds;
Clock.innerHTML = timeString;
window.setTimeout("tick();", 100);
}
window.onload = tick;
-->
</script>
<div
id="Clock"></div>
<!--输出-->
相关文章推荐
- cocos2d-x&nbsp;获取系统当前时间
- asp.net使用javascript实现不刷新页面获取当前时间
- asp.net 实现动态显示当前时间(不用javascript不考虑开销)
- JavaScript学习笔记之获取当前目录的实现代码
- JavaScript实现将当前的时间向前推三个月
- C语言实现获取LINUX当前时间
- 用javascript实现显示当前时间
- Js 获取当前日期时间及其它操作实现代码
- asp.net 实现动态显示当前时间(不用javascript不考虑开销)
- JavaScript获取当前时间源代码
- JavaScript获取系统当前日期和时间、星期几
- javascript获取当前时间
- 获取日期时间星期的"JAVASCRIPT代码"
- 最简单实现获取当前系统时间的方法
- AJAX 中需要 获取当前URL。发现 '&'符合之后的都不再读取。用JS实现
- JavaScript 获取当前系统日期和时间
- Javascript中获取系统的当前时间
- PHP date("Y-m-d H:i:s");获取当前时间 差8小时解决办法
- Javascript获取当前时间和日期的方法
- Javascript无刷新获取当前时间