aaa 8

Programming Learning Diary

GregorianCalendar 객체를 이용한 오늘의 날짜와 현재시간 나타내기

페이지 정보

작성일 19-11-19 19:52

본문



import java.io.IOException;

import java.io.PrintWriter;

import java.util.GregorianCalendar;


import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


/**

 * Servlet implementation class Date01

 */

@WebServlet("/Date01")

public class Date01 extends HttpServlet {

private static final long serialVersionUID = 1L;

       

    /**

     * @see HttpServlet#HttpServlet()

     */

    public Date01() {

        super();

        // TODO Auto-generated constructor stub

    }


/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

response.setContentType("text/html; charset=utf-8");

PrintWriter out = response.getWriter();

GregorianCalendar now = new GregorianCalendar();

String date=String.format("%TF",now);

String time=String.format("%TT",now);

out.println("<html>");

out.println("<head><title>날짜와 시각</title>");

out.println("</head>");

out.println("<body>");

out.println("오늘의 날짜 :"+date+"</br>");

out.println("현재의 시간 :"+time+"</br>");

out.println("</body>");

out.println("</html>");

}


/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

doGet(request, response);

}


}

0a02ed6710ff153e9d304a947e737d6a_1574160764_6268.png
 


댓글목록

등록된 댓글이 없습니다.