生活随笔
收集整理的這篇文章主要介紹了
显示长日期格式的系统时间
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
長格式是以“YYYY年MM月DD日 星期W”的格式來顯示的
應用JavaScript中的Date對象來實現的,創建一個Date對象時,如果該對象不包含任何構造參數,并且不通過setXXX()方法設置該對象中的年,月,日等值,那么該對象則表示當前系統時間的Date對象;
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>顯示長日期格式的系統時間</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><link href="CSS/style.css" rel="stylesheet"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script language="javascript"> /***顯示長日期格式的系統日期*/function getLangDate(){var dateObj = new Date(); //表示當前系統時間的Date對象 var year = dateObj.getFullYear(); //當前系統時間的完整年份值var month = dateObj.getMonth()+1; //當前系統時間的月份值 var date = dateObj.getDate(); //當前系統時間的月份中的日var day = dateObj.getDay(); //當前系統時間中的星期值var weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];var week = weeks[day]; //根據星期值,從數組中獲取對應的星期字符串 if(month<10){month="0"+month;}if(date<10){date="0"+date;}var newDate = year+"年"+month+"月"+date+"日 "+week;document.getElementById("dateStr").innerHTML = newDate;} </script></head><body onLoad="getLangDate()">
<table width="778" border="0" align="center" cellpadding="0" cellspacing="0" class="tableBorder"><tr><td height="183">
<table width="778" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td height="150" valign="top" background="Images/top_bg.gif" bgcolor="#EEEEEE"><table width="100%" height="53" border="0" cellpadding="0" cellspacing="0"><tr><td width="77%" height="18"> </td><td colspan="4"> </td></tr><tr><td> </td><td width="2%"><img src="Images/Top_flag.gif" width="3" height="7"></td><td width="8%"><a href="#" onClick="window.location.reload();">刷新頁面</a></td><td width="1%"><img src="Images/Top_flag.gif" width="3" height="7"></td><td width="12%"><a href="#" >關閉系統</a></td></tr></table><table width="98%" height="93" border="0" cellpadding="0" cellspacing="0"><tr><td align="right" valign="bottom" class="word_Green">當前登錄用戶:Remember</td></tr></table></td></tr><tr><td height="33" align="right" background="Images/navigation_bg.gif" bgcolor="#EEEEEE"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="3%"> </td><td width="25%"><div id="dateStr" class="word_Green"></div></td><td width="70%" align="right"><a href="#">首頁</a>┊<a href="">系統設置</a>┊<a href="#">讀者管理</a>┊<a href="#">圖書管理</a>┊<a href="#">圖書借還</a>┊<a href="#">系統查詢</a>┊<a href="#">排行榜</a>┊<a href="">更改口令</a>┊<a href="#">退出系統</a></td><td width="2%"> </td></tr></table></td></tr>
</table></td></tr><td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" bgcolor="#FFFFFF"><table width="99%" height="180" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="tableBorder_gray"><tr><td height="178" align="center" valign="top" style="padding:5px;"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="20" align="right" valign="middle" class="word_orange">當前位置:首頁 >>> </td></tr><tr><td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="57" background="Images/main_booksort.gif"> </td></tr><tr><td height="72" valign="top" background="Images/main_booksort_1.gif"><table width="100%" height="63" border="0" cellpadding="0" cellspacing="0"><tr><td width="2%"> </td><td width="96%" align="center" valign="top"><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bordercolordark="#D2E3E6" bordercolorlight="#FFFFFF"><tr align="center"><td width="6%" height="25">排名</td><td width="11%">圖書條形碼</td><td width="17%">圖書名稱</td><td width="15%">圖書類型</td><td width="16%">書架</td><td width="14%">出版社</td><td width="11%">作者</td><td>定價(元)</td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="39" align="right"></td></tr></table></td><td width="2%"> </td></tr></table></td></tr><tr><td height="19" background="Images/main_booksort_2.gif"> </td></tr></table></td></tr></table></td></tr>
</table></td></tr>
</table>
<table width="99%" height="72" border="0" align="center" cellpadding="-2" cellspacing="-2"><tr><td height="2" colspan="4"></td></tr><tr><td width="124" height="23"> </td><td valign="bottom" align="center"> CopyRight © 2007 www.mingrisoft.com 吉林省明日科技有限公司</td><td width="141"> </td></tr><tr><td height="28"> </td><td align="center">本站請使用IE6.0或以上版本 1024*768為最佳顯示效果</td><td> </td></tr><tr><td height="8"></td><td height="8"></td><td height="8"></td></tr></table></td></tr>
</table>
</body>
</html>
在獲得年份時,使用的是getFullYear()方法而不是用getYear()方法,getFullYear()方法以絕對數字的形式返回年份值
總結
以上是生活随笔為你收集整理的显示长日期格式的系统时间的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。