?
Solved

Dummy Q on the Server Time Dislay

Posted on 2003-03-07
13
Medium Priority
?
189 Views
Last Modified: 2010-04-01
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.......
0
Comment
Question by:pk55200
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 3

Expert Comment

by:NetWize
ID: 8088243
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8089512
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8092002
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pk55200
ID: 8093406
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8094153
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
 

Author Comment

by:pk55200
ID: 8100391
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8100465
>> 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
 

Author Comment

by:pk55200
ID: 8100700
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
 
LVL 14

Accepted Solution

by:
kennethxu earned 200 total points
ID: 8105631
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
 

Author Comment

by:pk55200
ID: 8108594
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
 

Author Comment

by:pk55200
ID: 8108626
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
 

Author Comment

by:pk55200
ID: 8108992
solved.

The tips is this

kk and shouldn't be KK.

:-)

0
 
LVL 14

Expert Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question