How to detect the timezone of a client?
Asked Answered
M

3

17

How to get client/request timezone in jsp?

Metallo answered 8/6, 2010 at 20:59 Comment(0)
A
26

Unfortunately this information is not passed in HTTP headers.

Usually you need cooperating JavaScript to fetch it for you.
Web is full of examples, here is one http://www.coderanch.com/t/486127/JSP/java/Query-timezone

Addressee answered 8/6, 2010 at 21:5 Comment(0)
C
1

you cannot get timezone, but you can get current time from client side.i.e. through javascript and than post back. On server side, you can convert that time to GMT/UTC. The UTC shows the TimeZone.

Curriery answered 8/6, 2010 at 21:22 Comment(0)
B
1

If you just need the local timezone in order to display local times to the user, I recommend representing all times in your service in UTC and rendering them in browsers as local times using Moment.js.

My general rule is to handle and store times in UTC everywhere except at the interface with the user, where you convert to/from local time. The advantage of UTC is that you never have to worry about daylight-saving adjustments.

Note that if you want to show the age of something (e.g. "posted 3 hours ago") you just need to compare the UTC timestamp with the current UTC time; no need to convert to local times at all.

Bypass answered 7/3, 2018 at 7:57 Comment(1)
I have a requirement, where I have to download data in pdf. So need to show date in user's timezone in the pdf. How do I do that.Craiova

© 2022 - 2024 — McMap. All rights reserved.