[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Time Zone and Locale question

Posted on 2004-08-18
13
Medium Priority
?
235 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 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