• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
josuva moorthy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
1
Android Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use Client Locale like
Locale clientLocale = request.getLocale();
Calendar calendar = Calendar.getInstance(clientLocale);
TimeZone clientTimeZone = calendar.getTimeZone();
 
josuva moorthy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
1
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use java script to find client timezone offset and send to a server to calculate clients timezone
 
josuva moorthy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be sure that you have a fallback default for cases when the user has JavaScript disabled.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic