JSP項(xiàng)目中如何實(shí)現(xiàn)實(shí)時(shí)顯示系統(tǒng)時(shí)間?相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
JSP顯示當(dāng)前系統(tǒng)時(shí)間的四種方式:
第一種java內(nèi)置時(shí)間類實(shí)例化對(duì)象:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > My JSP 'time4.jsp' starting page <% java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); java.util.Date currentTime = new java.util.Date(); String time = simpleDateFormat.format(currentTime).toString(); out.println("當(dāng)前時(shí)間為:"+time); %>