Solved

Time Zone and Locale question

Posted on 2004-08-18
13
229 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
form submissions on a web page 2 142
constuctor calling other constructor 2 74
Set up Wildfly 10 8 325
instanceof  operator in java 26 73
Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
Hyena v12.2 is now available for downloading and is available in English, French, German and Spanish versions.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

743 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