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.......
pk55200Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NetWizeCommented:
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?)
0
kennethxuCommented:
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>
0
kennethxuCommented:
a better example of javascript display time and data:
code: http://www.js-examples.com/example/?ex=971&mode=1
result: http://www.js-examples.com/example/?ex=971&mode=2
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

pk55200Author Commented:
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??
0
kennethxuCommented:
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>");
%>
0
pk55200Author Commented:
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??
0
kennethxuCommented:
>> 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?
0
pk55200Author Commented:
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.

0
kennethxuCommented:
use this:
df.setTimeZone( TimeZone.getTimeZone( "GMT+8:00" ) );
out.println(df.format(tm));

the cause is that your application server use GMT as its local timezone. the code above should adjust it for your application code. or you can get your administrator fix the timeznoe for your application server.
the output of the same code in my server is:

Local time: 3:12 PM EST
GMT time: 8:12 PM GMT

HTH
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pk55200Author Commented:
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...
0
pk55200Author Commented:
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...
0
pk55200Author Commented:
solved.

The tips is this

kk and shouldn't be KK.

:-)

0
kennethxuCommented:
you need to play arround with k, K, h and H, double or single to get what you want. thanks :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.