html代码,在一个页面中放三个时间的代码,应该怎么弄?

html代码,在一个页面中放三个时间的代码,应该怎么弄?,第1张

北京是东八区,伦敦是0时区,纽约是西五区,东边时间早于西边,因此北京和伦敦相差8个小时,纽约相差13个小时。
<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date()
var h1=todaygetHours(), h2=h1+8, h3=h1-13
var m=todaygetMinutes()
var s=todaygetSeconds()
// add a zero in front of numbers<10
h2=checkTimeH(h2)
h3=checkTimeH(h3)
m=checkTime(m)
s=checkTime(s)
documentgetElementById('bj')innerHTML=h1+":"+m+":"+s
documentgetElementById('ld')innerHTML=h2+":"+m+":"+s
documentgetElementById('ny')innerHTML=h3+":"+m+":"+s
t=setTimeout('startTime()',500)
}
function checkTimeH(i)
{
if (i>23) i-=24;
if (i<0) i+=24;
return i
}
function checkTime(i)
{
if (i<10)
{i="0" + i}
return i
}
</script>
</head>
<body onload="startTime()">
北京时间<div id="bj"></div><br />
伦敦时间<div id="ld"></div><br />
纽约时间<div id="ny"></div>
</body>
</html>

<script language=JavaScript>
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;}
function startclock () {
stopclock();
showtime();}
function showtime () {
var now = new Date();
var hours = nowgetHours();
var minutes = nowgetMinutes();
var seconds = nowgetSeconds()
var timeValue = "" +((hours >= 12) "下午 " : "上午 " )
timeValue += ((hours >12) hours -12 :hours)
timeValue += ((minutes < 10) ":0" : ":") + minutes
timeValue += ((seconds < 10) ":0" : ":") + seconds
documentclockthetimevalue = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;}
</SCRIPT>
<body onload=startclock()>
<form name=clock >
<input name=thetime style="font-size: 9pt;color:#000000;border:0" size=12>
</body>

哈~用JS!看这个!我这个简单!下面还有时钟~不要可以删除
用js网页会d出一个阻止框!记得点允许~
<html>
<head>
<script type="text/javascript">
var d=new Date()//为日期命名
documentwrite("今天是:"+dgetFullYear()+"年")//返回年
documentwrite(dgetMonth()+"月")//返回月,月是从0-11的~所以显示的是当前月份-1若非要显示当前月份!把这条删了,换用这条语句:documentwrite((dgetMonth()+1)+"月")
documentwrite(dgetDate()+"日")//返回日
var weekday=new Array(7)//建立一个星期的数组
weekday[0]="星期日"
weekday[1]="星期一"
weekday[2]="星期二"
weekday[3]="星期三"
weekday[4]="星期四"
weekday[5]="星期五"
weekday[6]="星期六"
documentwrite(" " + weekday[dgetDay()])//输出星期
function startTime()//以下为一个时钟!附加的!不要可以删除
{
var today=new Date()
var h=todaygetHours()
var m=todaygetMinutes()
var s=todaygetSeconds()
m=checkTime(m)
s=checkTime(s)
documentgetElementById('txt')innerHTML=h+":"+m+":"+s
t=setTimeout('startTime()',500)
}
function checkTime(i)
{
if (i<10)
{i="0" + i}
return i
}
//上面的是时钟
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>
</html>

代码提示:将下面的代码复制到〈BODY〉区
<script language="JavaScript">
<!--
function CalConv()
{
FIRSTYEAR = 1998;
LASTYEAR = 2031;
today = new Date();
SolarYear = todaygetFullYear();
SolarMonth = todaygetMonth() + 1;
SolarDate = todaygetDate();
Weekday = todaygetDay();
LunarCal = [
new tagLunarCal( 27, 5, 3, 43, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1 ),
new tagLunarCal( 46, 0, 4, 48, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 ), / 88 /
new tagLunarCal( 35, 0, 5, 53, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ), / 89 /
new tagLunarCal( 23, 4, 0, 59, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 42, 0, 1, 4, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 31, 0, 2, 9, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 ),
new tagLunarCal( 21, 2, 3, 14, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 ), / 93 /
new tagLunarCal( 39, 0, 5, 20, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 28, 7, 6, 25, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 ),
new tagLunarCal( 48, 0, 0, 30, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 ),
new tagLunarCal( 37, 0, 1, 35, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 ), / 97 /
new tagLunarCal( 25, 5, 3, 41, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),
new tagLunarCal( 44, 0, 4, 46, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),
new tagLunarCal( 33, 0, 5, 51, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 22, 4, 6, 56, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ), / 101 /
new tagLunarCal( 40, 0, 1, 2, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 30, 9, 2, 7, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ),
new tagLunarCal( 49, 0, 3, 12, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1 ),
new tagLunarCal( 38, 0, 4, 17, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0 ), / 105 /
new tagLunarCal( 27, 6, 6, 23, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 ),
new tagLunarCal( 46, 0, 0, 28, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0 ),
new tagLunarCal( 35, 0, 1, 33, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ),
new tagLunarCal( 24, 4, 2, 38, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ), / 109 /
new tagLunarCal( 42, 0, 4, 44, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ),
new tagLunarCal( 31, 0, 5, 49, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 ),
new tagLunarCal( 21, 2, 6, 54, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ),
new tagLunarCal( 40, 0, 0, 59, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 ), / 113 /
new tagLunarCal( 28, 6, 2, 5, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 ),
new tagLunarCal( 47, 0, 3, 10, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1 ),
new tagLunarCal( 36, 0, 4, 15, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 ),
new tagLunarCal( 25, 5, 5, 20, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ), / 117 /
new tagLunarCal( 43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 ),
new tagLunarCal( 32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0 ),
new tagLunarCal( 22, 3, 2, 36, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0 ) ];
/ 民国年每月之日数 /
SolarCal = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
/ 民国年每月之累积日数, 平年与闰年 /
SolarDays = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 397 ];
AnimalIdx = ["马", "羊", "猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇" ];
LocationIdx = [ "南", "东", "北", "西" ];
if ( SolarYear <= FIRSTYEAR || SolarYear > LASTYEAR ) return 1;
sm = SolarMonth - 1;
if ( sm < 0 || sm > 11 ) return 2;
leap = GetLeap( SolarYear );
if ( sm == 1 )
d = leap + 28;
else
d = SolarCal[sm];
if ( SolarDate < 1 || SolarDate > d ) return 3;
y = SolarYear - FIRSTYEAR;
acc = SolarDays[ leap14 + sm ] + SolarDate;
kc = acc + LunarCal[y]BaseKanChih;
Kan = kc % 10;
Chih = kc % 12;
Location = LocationIdx[kc % 4];
Age = kc % 60;
if ( Age < 22 )
Age = 22 - Age;
else
Age = 82 - Age;
Animal = AnimalIdx[ Chih ];
if ( acc <= LunarCal[y]BaseDays ) {
y--;
LunarYear = SolarYear - 1;
leap = GetLeap( LunarYear );
sm += 12;
acc = SolarDays[leap14 + sm] + SolarDate;
}
else
LunarYear = SolarYear;
l1 = LunarCal[y]BaseDays;
for ( i=0; i<13; i++ ) {
l2 = l1 + LunarCal[y]MonthDays[i] + 29;
if ( acc <= l2 ) break;
l1 = l2;
}
LunarMonth = i + 1;
LunarDate = acc - l1;
im = LunarCal[y]Intercalation;
if ( im != 0 && LunarMonth > im ) {
LunarMonth--;
if ( LunarMonth == im ) LunarMonth = -im;
}
if ( LunarMonth > 12 ) LunarMonth -= 12;
today=new Date();
function initArray(){
thislength=initArrayargumentslength
for(var i=0;i<thislength;i++)
this[i+1]=initArrayarguments[i] }
var d=new initArray("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
documentwrite("<span class=\"jsdhtml\"> ", todaygetYear()," 年 ",todaygetMonth()+1," 月 ",todaygetDate()," 日 ",d[todaygetDay()+1],"");
documentwrite( "<span class=\"jsdhtml\"><u> 农历 " + LunarMonth + "月" + LunarDate + "日</u>" );
documentwrite( "煞" + Location + " 冲" + Animal + Age + "岁</span>" );
return 0;
}
/ 求此民国年是否为闰年, 返回 0 为平年, 1 为闰年 /
function GetLeap( year )
{
if ( year % 400 == 0 )
return 1;
else if ( year % 100 == 0 )
return 0;
else if ( year % 4 == 0 )
return 1;
else
return 0;
}
function tagLunarCal( d, i, w, k, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13) {
thisBaseDays = d; / 到民国 1 月 1 日到农历正月初一的累积日数 /
thisIntercalation = i; / 闰月月份 0==此年没有闰月 /
thisBaseWeekday = w; / 此年民国 1 月 1 日为星期几再减 1 /
thisBaseKanChih = k; / 此年民国 1 月 1 日之干支序号减 1 /
thisMonthDays = [ m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13 ]; / 此农历年每月之大小, 0==小月(29日), 1==大月(30日) /
}
//-->
CalConv();
</script>

<iframe src=" ><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
table {
width: 230px;
margin: auto;
text-align: center;
border: 1px solid darkcyan;
border-bottom: 3px double darkcyan;
box-shadow: 0 1px 2px darkcyan;
}

th,
td {
border: 1px solid darkcyan;
}

today {
color: red;
}
</style>
<script>
//判断当前年份是否是闰年(闰年2月份有29天,平年2月份只有28天)
function isLeap(year) {
return year % 4 == 0  (year % 100 != 0  1 : (year % 400 == 0  1 : 0)) : 0;
}
var i, k,
today = new Date(), //获取当前日期
y = todaygetFullYear(), //获取日期中的年份
m = todaygetMonth(), //获取日期中的月份(需要注意的是:月份是从0开始计算,获取的值比正常月份的值少1)
d = todaygetDate(), //获取日期中的日(方便在建立日期表格时高亮显示当天)
firstday = new Date(y, m, 1), //获取当月的第一天
dayOfWeek = firstdaygetDay(), //判断第一天是星期几(返回[0-6]中的一个,0代表星期天,1代表星期一,以此类推)
days_per_month = new Array(31, 28 + isLeap(y), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31), //创建月份数组
str_nums = Mathceil((dayOfWeek + days_per_month[m]) / 7); //确定日期表格所需的行数
documentwrite("<table cellspacing='0'><tr><td colspan ='7'>" + y + "年" + (m + 1) + "月" + "</td></tr>");
documentwrite("<tr><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>"); //打印表格第一行(显示星期)
for(i = 0; i < str_nums; i += 1) { //二维数组创建日期表格
documentwrite('<tr>');
for(k = 0; k < 7; k++) {
var idx = 7  i + k; //为每个表格创建索引,从0开始
var date = idx - dayOfWeek + 1; //将当月的1号与星期进行匹配
(date <= 0 || date > days_per_month[m])  date = ' ': date = idx - dayOfWeek + 1; //索引小于等于0或者大于月份最大值就用空表格代替
date == d  documentwrite('<td class="today">' + date + '</td>') : documentwrite('<td>' + date + '</td>'); //高亮显示当天
}
documentwrite('</tr>');
}
documentwrite('</table>');
</script>
</head>
<body>
</body>
</html>

<!--setInterval实时显示时间-->
<p id="time1" style="color: blueviolet;"></p>
<script>
function mytime(){
var a = new Date();
var b = atoLocaleTimeString();
var c = atoLocaleDateString();
documentgetElementById("time1")innerHTML = c+"&nbsp"+b;
}
setInterval(function() {mytime()},1000);
</script>

<script language=JavaScript>
today=new Date();
function initArray(){
thislength=initArrayargumentslength
for(var i=0;i<thislength;i++)
this[i+1]=initArrayarguments[i]}
var d=new initArray(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六");
documentwrite(
"<font color=#FF6600 style='font-size:9pt;font-family: 宋体'> ",
todaygetYear(),"年",
todaygetMonth()+1,"月",
todaygetDate(),"日 ",
d[todaygetDay()+1],
"</font>" );
</script>
我在网页中加入了上面代码以显示时间,比如今天是1月11日,如何将其显示为01月11日


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/12677222.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-27
下一篇 2023-05-27

发表评论

登录后才能评论

评论列表(0条)

保存