package com.mhb; import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.*; import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class TimeServlet extends HttpServlet { public void init() throws ServletException {
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
21 response.setContentType("text/html;charset=utf-8");
22 PrintWriter out = response.getWriter();
23 Date nowDate = new Date(System.currentTimeMillis());
24 SimpleDateFormat time = new SimpleDateFormat("yyyy年MM月dd日-HH时mm分ss秒");
25 out.print("当前系统时间为:"+ time.format(nowDate));
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
} public void destroy() {
super.destroy();
}
}
浏览器显示: