Solved

Time Zone and Locale question

Posted on 2004-08-18
13
231 Views
Last Modified: 2010-04-01
Hii All,

I have to get the clarification on timezone and locale settings.

In our webapplication, the db is hosted in germany. But we have clients from america, using our web-client. All the data calculations in the backend are using central european timezone. So, clients in america are getting the date time with a time representation in central european timezone (b'coz the display of date time is not considering timezone).

Now, we want to use the timezone considerations in our display. So, i have the following question:

1) Is it good to handle the timezone settings in the client side OR in server side (db)?
2) If we do it in client side, how can i get the timezone settings of the user??
3) Is timezone bundled with locale?? B'coz we are setting the OS locale to en_US (purposely).

I have gone thru the java docs, but i m not getting a clear idea.
Can someone help?

Regards
aks
0
Comment
Question by:aks143
  • 5
  • 5
  • 3
13 Comments
 

Author Comment

by:aks143
ID: 11830082
i got the answer for my first and second asked question.

Applications may be able to find out about the offset of the user's current time zone from GMT by using some client-side JavaScript code, or they may let the user specify the current time zone as part of a user profile.

source : http://java.sun.com/developer/technicalArticles/Intl/MultilingualJSP/

I am replacing my two question with the next one:

Q) Which DateFormat function should i use, if i already have date in (ISO format -- YYYY-MM-DD) to apply timezone.

Regards,
aks
0
 
LVL 1

Accepted Solution

by:
TomBruser earned 150 total points
ID: 11831870
I'm assuming that by your ISO formatted date that you mean that you have a String containing your date information as Date objects don't contain formatting.

First you need to create a Date object from the String:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
sdf.setTimeZone(TimeZone.getTimeZone("EST")); // Example of how to set the DateFormat object to the EST time zone
// sdf.setTimeZone(TimeZone.getTiemZone("GMT-5:00")); <-- An alternate way to set the TimeZone
Date date = sdf.parse(dateString); // dateString is the String containing your formatted date as text.

Now that you have a Date object, you can change the way it is displayed using another SimpleDateFormat object:

SimpleDateFormat newdf = new SimpleDateFormat("MM/dd/yyyy z");
newdf.setTimeZone(TimeZone.getTimeZone("EST"));
String formatteddate = newdf.format(date);

TimeZone is not bundled with Locale as a Locale may contain multiple time zones.  Note: You will need to take care in how you store your dates as well as how you retrieve them.  Set your time zone explicitely.  I recommend converting and storing everything as GMT and only deviating from GMT upon retrieval and display.
0
 
LVL 92

Expert Comment

by:objects
ID: 11837519
> Q) Which DateFormat function should i use, if i already have date in (ISO format -- YYYY-MM-DD) to apply timezone.

DateFormat format =- DateFormat.getDateInstance(dateStyle, locale)

(or getDateTimeInstance() if you also want the time displayed).
 
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 92

Expert Comment

by:objects
ID: 11837521
that should have been:

DateFormat format = DateFormat.getDateInstance(dateStyle, locale);

:)
0
 
LVL 1

Expert Comment

by:TomBruser
ID: 11841303
That's all good and fine if there is a static field in DateFormat defined for his current date format, however I don't see one.  Which one would he use to populate the dateStyle field?  I chose SimpleDateFormat because it is a bit more straightforward and unless he's processing hundreds of dates per second should perform just fine in his application.
0
 
LVL 1

Expert Comment

by:TomBruser
ID: 11841334
Also, I don't believe locale will handle his timezone.  Please correct me if I'm wrong.
0
 

Author Comment

by:aks143
ID: 11880319
hii,

well...sorry for coming back late. But i believe TomBruser get his share.
Thanks
aks

0
 
LVL 92

Expert Comment

by:objects
ID: 11887310
How does that take the locale into account?
0
 
LVL 1

Expert Comment

by:TomBruser
ID: 11888427
Locale isn't really even necessary if he's explicitely formatting his Date.  His main issue was in retrieving dates that were originally Strings, storing them, retrieving them again, and then displaying them properly while keeping time zone integrity.
0
 
LVL 92

Expert Comment

by:objects
ID: 11888457
> Locale isn't really even necessary if he's explicitely formatting his Date.

Why not, dates are displayed differently depending on location.
0
 
LVL 1

Expert Comment

by:TomBruser
ID: 11888564
They're not necessary if he wants to display the date using just the one format.  He only asked if the timezone was bundled with the locale.  Had he asked about displaying the date in formats relevant to the locale, I would have given him an answer similar to yours.  Currently he's stating that he wants to display the time with the correct offset based on the user's time zone.  Even if he has retrieved the offset from the user via Javascript or whatnot, he still doesn't know the locale of the user.  Multiple locales exist in many time zones and multiple time zones exist in many locales.  If he needs locale as well as timezone then your answer is definitely the better answer for him.
0
 
LVL 92

Expert Comment

by:objects
ID: 11888652
Thanks for the clarification :)
0
 

Author Comment

by:aks143
ID: 11890089
ohh..i m again late. Well, Objects.....TomBruser last comment is what i was asking for!! i never said i need format depending upon locale. I already have a specified format...i just need offset.

Anyway, thanks for all your inputs.

regards
aks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat users xml 7 130
jersey maven project error 7 143
stateless EJB with glassfish 2 73
maven not picking latest jar instead picking old jar from .m2 12 25
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 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