javascript代码,看的懂的教我。

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:58:39
<script language="javascript">
function tick() {
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var today;
today = new Date();
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"

这是一段显示当前时间的代码
<script language="javascript">
function tick() {
//初始化
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var today;

today = new Date(); //获得当前时间
intHours = today.getHours(); //时
intMinutes = today.getMinutes(); //分
intSeconds = today.getSeconds(); //秒

//根据具体时间显示是为12小时制,并用中文标明是上午、下午还是中午、午夜
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+":";
}