如何从HttpServletRequest获取Java中的客户端时区? [英] how to get client's time zone in java from HttpServletRequest?
本文介绍了如何从HttpServletRequest获取Java中的客户端时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当服务器和客户端位于不同的时区时,我可以使用HttpServletRequest在java中获取客户端的时区吗?
When server and client are in different time zones, can i get client's time zone in java using HttpServletRequest?
我正在尝试创建'Calender'的实例像这样使用客户的'Locale',
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?
推荐答案
不幸的是,时区信息未通过在 HTTP请求
。
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.
这篇关于如何从HttpServletRequest获取Java中的客户端时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文