?
Solved

Time Zone and Locale question

Posted on 2004-08-18
13
Medium Priority
?
234 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
[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
  • 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 600 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
Independent Software Vendors: 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!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The Summer 2017 Scholarship Winners have been announced!
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

770 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