网站首页
网站导航
Ctrl+D收藏
首 页
代码段
源码包
文档库
工具箱
代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
JS
】
在网页上显示当前时间
作者:
starstroll
/ 发布于
2014/9/22
/
608
<html> <head> <title>Javascript clock</title> <head> <style type="text/css"> form,label { font-family:arial, sans-serif, helvetica, "times new roman"; font-size:10pt; /* increase or decrease the value to change the size of the font */ } h1 { font-family:arial, sans-serif, helvetica, "times new roman"; } </style> <script type="text/javascript"> <!-- hide the code from old browsers that do not support javascript /* Original: daniusr You are welcomed to modify this script to your needs. This script retrieves the time from the internal system clock, so it is up to you to make sure the time is accurate or correct. */ function clock() { var today = new Date(); var hours = today.getHours(); var minutes = today.getMinutes(); var seconds = today.getSeconds(); var time_holder; // holds the time //if the first radio button is checked display 12-hours format time if(timeForm.stime[0].checked) { // add "AM" or "PM" if the 12-hours format is chosen var ampm = ((hours >= 12) ? " PM" : " AM"); // convert the hour to 12-hours format // javascript returns midnight as 0, but since the time is in the 12-hours format // force javascript to return 12 hours = ((hours == 0) ? "12" : (hours > 12) ? hours - 12 : hours); // add a leading zero if less than 10 minutes = ((minutes < 10) ? "0" + minutes : minutes); seconds = ((seconds < 10) ? "0" + seconds : seconds); time_holder = hours + ":" + minutes + ":" + seconds + ampm; document.getElementById('jsClock').innerHTML = time_holder; } if(timeForm.stime[1].checked) { // add a leading zero if less than 10 hours = ((hours < 10) ? "0" + hours : hours); minutes = ((minutes < 10) ? "0" + minutes : minutes); seconds = ((seconds < 10) ? "0" + seconds : seconds); time_holder = hours + ":" + minutes + ":" + seconds; document.getElementById('jsClock').innerHTML = time_holder; } if((!timeForm.stime[0].checked) && (!timeForm.stime[1].checked)) { document.getElementById('jsClock').innerHTML = "Please select a time format."; } // keep the clock ticking setTimeout("clock()", 1000); } // end hiding --> </script> </head> <body onload="javascript:clock()"> <h1 id="jsClock" style="margin:0" align="center"></h1> <form name="timeForm" style="margin:0"> time format: <label for="ci"><input type="radio" name="stime" id="ci">12-hours format</label> <label for="mi"><input type="radio" name="stime" id="mi">24-hours format</label> </form> </body> </html>
评论列表
本站所提供的代码,版权归原作者所有,若有侵犯作者版权,请与我们联系,我们将立即删除或修改。谢谢!
本站所有代码发布及提供者。
试试其它关键字
显示当前时间
同语言下
.
Jquery搜索框获取回车事件
.
H5页面添加倒计时,然后自动跳转
.
通过user-agent判断h5页面是在哪个手机App(QQ、微信
.
nginx 禁止未绑定的域名访问
.
JavaScript 获取按键,并屏蔽系统 Window 事件
.
H5之只允许微信浏览器打开,禁止从外部浏览器访问
.
微信打开网址添加在浏览器中打开提示的办法
.
实现JS复制、粘贴,Chrome/Firefox下可用
.
video视频播放,play()、pause()、duration时长、onen
.
HTML5实现MP3上传前的预览和播放时长的获取
可能有用的
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
判断用户输入的是否为IP地址
starstroll
贡献的其它代码
(
2
)
.
jquery库与其他库冲突的问题解决-jquery.noConflict()
.
在网页上显示当前时间
地图
本站
我们
服务
版权
联系
回馈
博客