简体   繁体   English

如何在不使用Cookie的情况下在Spring Controller中获取客户端时区偏移?

[英]How get client timezone offset in spring controller without using cookie?

I'm trying to show dates on page, now server time is shown, the way I found is set cookie value in browser and use it in controller, but first time page is loading cookie value isn't settled. 我试图在页面上显示日期,现在显示服务器时间,我发现的方法是在浏览器中设置cookie值并在控制器中使用它,但是第一次加载cookie值的页面没有解决。 The only possible way I see is use ajax, Is there any way get timezone offset in controller without using cookie? 我看到的唯一可能的方法是使用ajax,是否有任何方法可以在不使用cookie的情况下获取控制器中的时区偏移?

Sorry but there is really no way of getting timezone offset on the server side unless you explicitly pass it from the client. 抱歉,除非您从客户端显式传递时区,否则实际上无法在服务器端获取时区偏移。 A possible work around is on the server side pass all your dates to the client in some standard timezone (probably GMT) then use javascript to localize the page to the right timezone. 可能的解决方法是在服务器端将所有日期传递到某个标准时区(可能是GMT)中的客户端,然后使用javascript将页面本地化到正确的时区。

A library I have used in the past that makes these timzones manipulations much easier is called moment.js but it is not necessary for you to use. 我过去使用过的使这些timzones操作更加容易的库称为moment.js,但您不必使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM