aspose file tools*
The moose likes Servlets and the fly likes How to get current date based on time zone or locale, or user preference? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get current date based on time zone or locale, or user preference?" Watch "How to get current date based on time zone or locale, or user preference?" New topic
Author

How to get current date based on time zone or locale, or user preference?

josuva moorthy
Greenhorn

Joined: Apr 05, 2010
Posts: 11
My web application is deployed in the US I will get US time regardless of the client's country. But if the client is in India, he should get Indian time, either using the time zone or locale or user preference. What should I do?

Example : A user is doing a transaction from India morning 8.00 am .and user searches for the transaction he found the time is US date and time ,user get confused
So we need to change the time as local time .

What I need to do

Please help me
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

use Client Locale like
Locale clientLocale = request.getLocale();
Calendar calendar = Calendar.getInstance(clientLocale);
TimeZone clientTimeZone = calendar.getTimeZone();
josuva moorthy
Greenhorn

Joined: Apr 05, 2010
Posts: 11
Thanks for your reply

If your having any sample code for this requirement or any link or any docs related to this
It would be helpful.

Thanks in advance
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

Hi josuva,
try this link
http://forums.devarticles.com/java-development-38/jsp-getting-the-client-system-date-and-time-to-display-on-19428.html
and let me know if you face any issue, i would be happy to help.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

you can use java script to find client timezone offset and send to a server to calculate clients timezone
josuva moorthy
Greenhorn

Joined: Apr 05, 2010
Posts: 11
Seetharaman Venkatasamy wrote:you can use java script to find client timezone offset and send to a server to calculate clients timezone


Thanks for your reply . I have get the time offset from the javascript as -330 . How I need to manipulate with date which I have in US date format. can you please help me
If possible send me the sample code

I am not aware how to manipulate date with the offset in java. can you help me


josuva moorthy
Greenhorn

Joined: Apr 05, 2010
Posts: 11
harshvardhan ojha wrote:Hi josuva,
try this link
http://forums.devarticles.com/java-development-38/jsp-getting-the-client-system-date-and-time-to-display-on-19428.html
and let me know if you face any issue, i would be happy to help.



Thanks for the reply .The first part of the code which help me how to use the locale .I am checking a code to get the timeOffset from the javascript (client Side )
read from the server side and change the date while displaying .

Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61190
    
  66

Be sure that you have a fallback default for cases when the user has JavaScript disabled.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get current date based on time zone or locale, or user preference?