Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get client's time zone in java from HttpServletRequest? [duplicate]

When server and client are in different time zones, can i get client's time zone in java using HttpServletRequest?

I am trying to create an instance of 'Calender' using client's 'Locale' like this,

Calendar calendar = Calendar.getInstance(request.getLocale());
TimeZone clientTimeZone = calendar.getTimeZone();

But this is giving me Server's time zone only.

Is this method wrong? Is there any other way to get Client's time zone in Server?

like image 305
Noor Khan Avatar asked Mar 18 '14 12:03

Noor Khan


People also ask

How to get client TimeZone in Java?

Calendar calendar = Calendar. getInstance(request. getLocale()); TimeZone clientTimeZone = calendar. getTimeZone();

How do I find client time zone on my server?

The client's timezone offset could be detected by using the Date object's getTimezoneOffset() method. The getTimezoneOffset() method returns the time difference between UTC time and local time, that is the time offset, in minutes. This offset is changed by dividing by 60 and negating the result.

How do I get the TimeZone from http request Spring boot?

Retrieve the current time zone from the given request, using the TimeZoneAwareLocaleResolver bound to the request by the DispatcherServlet (if available), falling back to the system's default time zone. Note: This method returns null if no specific time zone can be resolved for the given request.

How does Java get TimeZone?

Typically, you get a TimeZone using getDefault which creates a TimeZone based on the time zone where the program is running. For example, for a program running in Japan, getDefault creates a TimeZone object based on Japanese Standard Time.


1 Answers

Unfortunately the time zone information's are not passed in HTTP request.

But there are a work around for this case.

Check this answer and this one. it may help you.

like image 94
Salah Avatar answered Oct 06 '22 13:10

Salah