This part of the code is correct:
Calendar calendar = new GregorianCalendar(request.getLocale());
Basically a Calendar instance is created in the file :
prefers Locale to let the client accept content based on the Accept-Language header
Your error is converting Calendar to Date here:
calendar.getTime()
java.util.Date class is a time zone agnostic, and always its default implementation of toString() always uses the time zone of the system (your servers). If you want to format the current server time in the clients time zone, use the following code fragment:
DateFormat df = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG, request.getLocale() ); df.format(new Date());
One final note: this is the time it displays on the server using the clientβs time zone. This is not the clients time set in the browser (operating system). To find out what is the time zone on the client, you need to explicitly send the current time of the client to the HTTP request.
source share