Khaled
That's unusual. On my local machine, if I change the local timezone (W2k,
Tomcat 4), and restart the server, it automatically picks up the new local
timezone as default, as opposed to GMT. On a remote server (Linux Rhat,
T4), the same is true - displyDate() gives the local time according to
whatever the local timezone is.
Possibly this may be an os-jvm issue?
To get around this you could load the default TimeZone from the servlets
initialisation parameters in the web.xml file. This would mean you could
set it per server if required. So you would call:
format.setTimeZone(TimeZone.getTimeZone(initTimeZone));
where initTimeZone would be loaded by the servlets init method each time.
Hope this helps,
Andrew
Professional Java Servlets 2.3
http://www.amazon.com/exec/obidos/ASIN/186100561X
-----Original Message-----
From: Khaled Ayoubi [mailto:javabk76@h...]
Sent: 05 June 2002 12:49
To: Java Server
Subject: [pro_java_server] RE: current time problem
Hi Andrew:
i test your JSP and it's work fine for
out.println(displayLADate() + " (LA)<br>");
out.println(displayESTDate2() + " (EST)<br>");
where i see different times according to time zone specified,
but in case of
out.println(displyDate() + " (HERE - Local server time)<br>");
i still get the GMT time,
i test this jsp locally and in remote server, and i got the same result.
i figuared out from your message that there is default server time, is it
configuration for the server that specifiy the timezone being used,
if so, i'm using tomcat, so how can i change this default setting to be
the time of the machine that is run on????
thanks again.
Regards
Khaled.
> Is your web application deployed locally? On my local machine the
example
correctly shows the local time for the specified TimeZone. In the default
case it uses GMT, as that's my default. Perhaps your server uses GMT as
default. When I ran the jsp below on both my local server and remote
server
it returned the default local time for "displyDate()" - ie GMT for GMT
machnine, but for "displayESTDate2()", correctly returned the Eastern
Standard Time.
---test.jsp---
<%@ page import="java.util.*,java.text.*" %>
<%!
private static String displayLADate()
{ Date d = new Date(System.currentTimeMillis());
DateFormat format = new java.text.SimpleDateFormat("dd-MM-yyyy
HH:mm");
format.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
return format.format(d);
}
private static String displayESTDate2()
{ Date d = new Date(System.currentTimeMillis());
DateFormat format = new java.text.SimpleDateFormat("dd-MM-yyyy
HH:mm");
format.setTimeZone(TimeZone.getTimeZone("EST"));
return format.format(d);
}
private static String displyDate()
{ Date d = new Date(System.currentTimeMillis());
DateFormat format = new java.text.SimpleDateFormat("dd-MM-yyyy HH:mm");
return format.format(d);
}
%>
<html>
<head><title>test</title></head>
<body text="#900000">
<%
out.println(displyDate() + " (HERE - Local server time)<br>");
out.println(displayLADate() + " (LA)<br>");
out.println(displayESTDate2() + " (EST)<br>");
%>
</body>
</html>
---end test.jsp---
This produced:
05-06-2002 11:36 (HERE)
05-06-2002 03:36 (LA)
05-06-2002 06:36 (EST)
If you run the above jsp, hopefully, you will see something similar, with
different times according to the TimeZone used. "HERE" is your servers
default which may be GMT, but by adapting the other methods to your
preferred TimeZone, you should be ok. Do you see different times as shown
in my output?
Hope this helps,
Andrew
Professional Java Servlets 2.3
http://www.amazon.com/exec/obidos/ASIN/186100561X
-----Original Message-----
From: Khaled Ayoubi [mailto:javabk76@h...]
Sent: 05 June 2002 06:16
To: Java Server
Subject: [pro_java_server] RE: current time problem
Hi:
this is work fine, but i still need to hard-coded the name of the
machine-place which i'm going to deploy my application on.
i'm wondering why i'm getting my machine time if i run this code in
local java application, while i'm getting the GMT time if i run it from my
web application??
is it from web application configuration, or other issue!!
thanks in advance
Regards.
Khaled
-----Original Message-----
From: Khaled Ayoubi [mailto:javabk76@h...]
Sent: 05 June 2002 07:46
To: Java Server
Subject: [pro_java_server] RE: current time problem
sorry for inconvience,
but this solution work fine in local java program,
but when i try it from my web application i still get the GMT time:
even with using
format.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
any more help??
Khaled