Thursday, 5 September 2013

How to do Auto refresh date in jsp


<%@ page import="java.io.*,java.util.*" %>
<html>
<head>
<title>How we can do Auto refresh date in jsp example</title>
</head>
<body>
<center>
<h2>Auto Refresh Date</h2>
<%
   // Set refresh, autoload time as 5 seconds
   response.setIntHeader("Refresh", 5);
   // Get current time
   Calendar calendar = new GregorianCalendar();
   String am_pm;
int datetoday = calendar.get(Calendar.DATE);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
   int hour = calendar.get(Calendar.HOUR);
   int minute = calendar.get(Calendar.MINUTE);
   int second = calendar.get(Calendar.SECOND);
   if(calendar.get(Calendar.AM_PM) == 0)
      am_pm = "AM";
   else
      am_pm = "PM";
   String CT = hour+":"+ minute +":"+ second +" "+ am_pm;
   out.println("Crrent Time: " + CT + "\n");
out.println("<br/>");
out.println("date (dd/mm/yyyy) :"+datetoday+month+year);
 out.println("<br/>");
out.println("date:"+datetoday);
out.println("month:"+month);
out.println("year:"+year);
%>
</center>
</body>
</html>

No comments:

Post a Comment