注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

勇气

终生读书

 
 
 

日志

 
 

一个简单的日历-标出当前日的即时时间  

2012-03-05 11:27:43|  分类: CSS+DIV简单布局 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

<html>

<head>
<title>一个简单的日历-标出当前日的即时时间</title>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">

<script language="JavaScript">
<!--
setCal()
function getTime() {
 var now = new Date()
 var hour = now.getHours()
 var minute = now.getMinutes()
 now = null
 var ampm = ""
 if (hour >= 12) {
  hour -= 12
  ampm = "下午"
 } else
  ampm = "上午"
 hour = (hour == 0) ? 12 : hour
 if (minute < 10)
  minute = "0" + minute
 return hour + ":" + minute + " " + ampm
}
function leapYear(year) {
 if (year % 4 == 0)
  return true
  return false
}

function getDays(month, year) {
 var ar = new Array(12)
 ar[0] = 31
 ar[1] = (leapYear(year)) ? 29 : 28
 ar[2] = 31
 ar[3] = 30
 ar[4] = 31
 ar[5] = 30
 ar[6] = 31
 ar[7] = 31
 ar[8] = 30
 ar[9] = 31
 ar[10] = 30
 ar[11] = 31
 return ar[month]
}

function getMonthName(month) {
 var ar = new Array(12)
 ar[0] = "1月"
 ar[1] = "2月"
 ar[2] = "3月"
 ar[3] = "4月"
 ar[4] = "5月"
 ar[5] = "6月"
 ar[6] = "7月"
 ar[7] = "8月"
 ar[8] = "9月"
 ar[9] = "10月"
 ar[10] = "11月"
 ar[11] = "12月"
 return ar[month]
}
function setCal() {
 var now = new Date()
 var year = now.getYear()
if (year<2000)
year=1900+year;
 var month = now.getMonth()
 var monthName = getMonthName(month)
 var date = now.getDate()
 now = null
 var firstDayInstance = new Date(year, month, 1)
 var firstDay = firstDayInstance.getDay()
 firstDayInstance = null
 var days = getDays(month, year)
 drawCal(firstDay + 1, days, date, monthName, year)
}
function drawCal(firstDay, lastDate, date, monthName, year) {
 var headerHeight = 50
 var border = 2
 var cellspacing = 4
 var headerColor = "midnightblue"
 var headerSize = "-1"
 var colWidth = 50
 var dayCellHeight = 10
 var dayColor = "darkblue"
 var cellHeight = 20
 var todayColor = "red"
 var timeColor = "purple"
 var text = ""
 text += '<CENTER>'
 text += '<TABLE BORDER=1'  + ' CELLSPACING=0'  + 'style="font-size: 9pt">'
 text +=  '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>'
 text +=   ''
 text +=    year+'年'+ monthName + '日历' 
 text +=   ''
 text +=  '</TH>'
 var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'
 openCol += '<FONT COLOR="' + dayColor + '">'
 var closeCol = '</FONT></TD>'
 var weekDay = new Array(7)
 weekDay[0] = "星期天"
 weekDay[1] = "星期一"
 weekDay[2] = "星期二"
 weekDay[3] = "星期三"
 weekDay[4] = "星期四"
 weekDay[5] = "星期五"
 weekDay[6] = "星期六"
 text += '<TR ALIGN="center" VALIGN="center"  style="font-size: 9pt">'
 for (var dayNum = 0; dayNum < 7; ++dayNum) {
  text += openCol + weekDay[dayNum] + closeCol
 }
 text += '</TR>'
 var digit = 1
 var curCell = 1
 for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
  text += '<TR ALIGN="right" VALIGN="top" style="font-size: 9pt">'
  for (var col = 1; col <= 7; ++col) {
   if (digit > lastDate)
    break
   if (curCell < firstDay) {
    text += '<TD></TD>';
    curCell++
   } else {
    if (digit == date) {
     text += '<TD HEIGHT=1>'
     text += '<FONT COLOR="' + todayColor + '">'
     text += digit
     text += '</FONT><BR>'
     text += '<FONT COLOR="' + timeColor + '" SIZE=2 style="font-size: 9pt">'
     text += '<CENTER>' + getTime() + '</CENTER>'
     text += '</FONT>'
     text += '</TD>'
    } else
     text += '<TD HEIGHT=' + cellHeight + '>' + digit + '</TD>'
    digit++
   }
  }
  text += '</TR>'
 }
 text += '</TABLE>'
 text += '</CENTER>'
 document.write(text)
}
//-->
</script>
<script language="JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
</head>

<body>

</body>
</html>


  评论这张
 
阅读(208)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018