Solved

Time Zone and Locale question

Posted on 2004-08-18
13
230 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now