用Jsp在页面上输出中国式日期代码是什么
- 提问者网友:ミ烙印ゝ
- 2021-06-06 10:32
- 五星知识达人网友:几近狂妄
- 2021-06-06 10:51
首先import两个包:java.util.*和java.text.*
然后用
<%
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
out.println(format.format(new Date()));
%>
- 1楼网友:佘樂
- 2021-06-06 12:44
-------------------------------------HTM代码-------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script> var count=0; //控制图片下标的全局变量 function changBg() { var time = new Date( ); //获得当前时间 //获得年、月、日,Date()函数中的月份是从0-11计算 var year = time.getYear(); var month = time.getMonth()+1; var date = time.getDate(); //获得小时、分钟、秒 var hour = time.getHours(); var minute = time.getMinutes(); var second = time.getSeconds(); //获得一个星期中的第几天,西方的星期是从星期日开始,星期六结束 var day = time.getDay(); if (minute < 10) //如果分钟只有1位,补0显示 { minute="0"+minute; } if (second < 10) //如果秒数只有1位,补0显示 { second="0"+second; } var apm="AM"; //默认显示上午: AM if (hour>12) //按12小时制显示 { hour=hour-12; apm="PM" ; } var weekday = 0; switch(time.getDay()){ case 0: weekday = "星期日"; break; case 1: weekday = "星期一"; break; case 2: weekday = "星期二"; break; case 3: weekday = "星期三"; break; case 4: weekday = "星期四"; break; case 5: weekday = "星期五"; break; case 6: weekday = "星期六"; break; } if(count<10) { count=count+1; } var url="F:\\images\\bg"+count+".jpg"; //这是背景图片的地址(这是动态更换背景图片,但是注意的是你要在F盘images文件夹里放对应的图片哦!比如我这里是:bg1.jpg,bg2.jpg,···bg10.jpg.我这里限制了10张,你可以自己随意修改张数) if(hour==13&&min==1) //这里判断是否到了13点1分 { document.body.background=url; //更换背景图片 //document.bgColor="red"; //更换背景颜色 } document.getElementById("time_id").value="今天是:"+year+"年"+month+"月"+date+"日"+weekday+" "+hour+":"+minute+":"+second+apm; //将本地系统时间显示在文本标记Id=“time_id”上 setTimeout("changBg()",1000); //1秒之后调用方法changBg()一次(只调用一次,要每隔一秒刷新一下时间,所以将这代码写在方法changBg()里面) } </script> </HEAD>
<BODY onload="changBg()"> <form name="frm"> <INPUT id="time_id" name="time" type="text" size="40"> </form> </BODY> </HTML> --------------------------------------------
以上代码你可以直接赋值到文本中,然后蒋文本的扩展名改为xxx.html。双击运行,你就可以看到效果了。希望对你有帮助!
- 2楼网友:迟山
- 2021-06-06 12:18
js代码输出,在那个地方都通用!
<script language="javascript1.2"> var isnMonth=new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); var isnDay = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); today = new Date(); Year = today.getYear(); Date = today.getDate(); if(document.all) document.title="今天是:"+Year+"年"+isnMonth[today.getMonth()]+Date+"日 "+isnDay[today.getDay()] </script>