JSP page display wrong time when compared to the server time
843836Feb 1 2005 — edited Feb 2 2005Hi,
This problem seems to weird but it is happening
I have web application running where time is displayed in the page. In this application time is very critical. Currently, time is an hour behind the orginal time.
I checked the server it is displaying proper time.
As a matter of troubleshooting, I wrote a java program and run the program in the same server, where the application is running. The java program returns me proper time , but JSP is still displaying time an hour behind. To trouble shoot further, I created a test jsp page to just display the time and accessed the time and the jsp displayed wrong time as well, an hour behind.
I am running[ tomcat 4.0.3 and j2sdk1.4.3 in suse linux enterprise server 9.0
My Java program
************************************************************************************
import java.util.*;
import java.text.*;
public class TestDate
{
public static void main(String s[])
{
try{
DateFormat DF = new SimpleDateFormat( "dd/MM/yyyy");
DateFormat DT = new SimpleDateFormat("hh:mm aa");
SimpleDateFormat fmt=new SimpleDateFormat("HH.mm");
Calendar cal= Calendar.getInstance();
java.util.Date dt=cal.getTime();
String curdt=DT.format(dt);
System.out.println("Server Time" + curdt + "\n");
int hh = cal.get(Calendar.HOUR);
int mm = cal.get(Calendar.MINUTE);
int aa = cal.get(Calendar.AM_PM);
System.out.println("Time" + hh +":"+mm+":"+aa+"\n");
}catch(Exception e) {
e.printStackTrace();
}
}
}
**********************************************************************
This display Time3:30:1
My JSP Page
****************************************************************************************
<%@ page import="java.util.*,java.text.*"%>
<%
Calendar calen;
calen = Calendar.getInstance();
int hh=calen.get(Calendar.HOUR);
int mm=calen.get(Calendar.MINUTE);
int aa=calen.get(Calendar.AM_PM);
%>
<%=hh%> <%=mm%> <%=aa%>
***************************************************************************************
This display 2 30 1
****************************************************************************************
When I run Date in linux server it gives 3:30 PM EST 2004
I am really confused, why this is happening, If you have any solutions or idea please post the solution.