Here is my code:
@RequestMapping(value="/test", method=RequestMethod.GET)
public @ResponseBody String test(HttpServletRequest request) {
Calendar calendar = new GregorianCalendar(request.getLocale());
String currentTime = calendar.getTime().toString();
return"Current Time: " + currentTime;
}
This is showing me this time:
Current Time: Fri Nov 30 22:45:42 UTC 2012
I am in the central time zone, so it should be showing me this:
Current Time: Fri Nov 30 14:45:42 CST 2012
Why am I getting the server time instead of the client time?
Your code executes on server irrespective where your client is. On server you will setup timezone for that machine, which will be used to calculate time. when you call
calendar.getTime()this timezone will be used.If you want client time zone, you need to send it and use something SimpleDateFormat to convert server time to client timezone.