Link to home
Start Free TrialLog in
Avatar of pk55200
pk55200

asked on

Dummy Q on the Server Time Dislay

Hi all, I manage to set the display time.

java.util.Date tm = new java.util.Date();
SimpleDateFormat df = new SimpleDateFormat("K:mm a");
out.println(df.format(tm));

But the output is this 8.05 AM. But my actual time is 3.45 pm.

How can I apply the LocaleTimeScale on it?

I try this,

java.util.Date tm = new java.util.Date();
SimpleDateFormat df = new SimpleDateFormat("K:mm a");
out.println(df.format(tm.toLocalepattern()));

//thrown me error.......
Avatar of NetWize
NetWize

So you want the server (who thinks it's 8:05 am) to create a String containing the date at your location (where it's 3:45 pm).

That would require the server to "know" from which time-zone you are calling him.

I think if you want the local time to appear on the page JavaScript would be easier to manage.

Or is it that the server runs at GMT and you want it to interpret his local time according to your timezone?(so is the server to display a SERVER-time, only shifted?)
do you want to display server time or client time? if run a browser in New York, and access a server in Paris, that 2 time is different.

if you want to display server time, you code is correct. check the server system clock if you find the time is not correct.

if you want to display client time, try this javascript:
<script>
var dt = new Date();
document.write(dt.toLocaleString());
</script>
Avatar of pk55200

ASKER

ken, i read one of your solution that you posted to help one fellow. Seems that you have expereicen in AS400.

My case is exactly the same. My AS400 system time is 1.00pm but when I code my coding, the date prompt me this, 8.45am.

Actually I want to server time. Not the client time. SOrry for didn;'t specify clearly. I undertand tha i must use somthing like locale...

And one more things, the time tha I specify is come with GST... is it because of that I couldn;t get he tim correctly??
do you mean your jsp/servlet server running on AS400, or just your database is on AS400?

>> My AS400 system time is 1.00pm
is this the GST or local time?

can you try this jsp page and let me know the result?

<%@page import="java.text.*, java.util.*" %>
<%
Date today = new Date();
SimpleDateFormat df = new SimpleDateFormat("K:mm a z");
out.println("Local time: " + df.format(today) + "<p>");
df.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
out.println("GMT time: " + df.format(today) + "<p>");
%>
Avatar of pk55200

ASKER

ken, this is what I got

Local time: 3:30 AM GMT+00:00
GMT time: 3:30 AM GMT

And frankly speaking. My current time (my country) is 11.44 am.

Yes, I am running everything on AS400. Including App. Server, Servlet, JSP and also DB.

WHat is happending for my time??
>> My current time (my country) is 11.44 am
where is your control? can you let me know the timezone your are in?

can you check if your AS400's server clock is correct?
Avatar of pk55200

ASKER

my AS400 show me the system time is 03/10/03 12:55:01

This is can be shown when I WRKACTJOB and the top of the screen show me clearly.

>>where is your control? can you let me know the timezone your are in?

My current time is the time that I show on the AS400. And regarding my time zone, I am in Malaysia. So, I think the time zone is Singaspore or Kuala Lumpur or Bangkok, Thailand.

ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pk55200

ASKER

ken,

my server now is 12:28:43 pm.

but my code display this,

Date today = new Date();
SimpleDateFormat df = new SimpleDateFormat("Kmmss a ");
df.setTimeZone( TimeZone.getTimeZone("GMT+8:00") );
out.println("Local time: " + df.format(today) + "<p>");

Local time : 02843 PM.

Ha....

It's ok when I try it b4 11.59.00 am.
But after the 12.00.00 pm, then everything strt from 00000

Ha...

How to correct. Ken serious speakig, I don't know how. You show me this time and I swear aI will remember how to do that for the rest of my life.... Ha...
Avatar of pk55200

ASKER

is it this,

Date today = new Date();
SimpleDateFormat df = new SimpleDateFormat("hhmmss aaa ");
df.setTimeZone( TimeZone.getTimeZone("GMT+8:00") );
out.println("Local time: " + df.format(today) + "<p>");


now, it's seem ok but scare later can match b4 12pm.
Ha...
Avatar of pk55200

ASKER

solved.

The tips is this

kk and shouldn't be KK.

:-)

you need to play arround with k, K, h and H, double or single to get what you want. thanks :)