不同的TimeZone输出错误的值

时间:2019-03-11 16:35:20

标签: postgresql timestamp timezone timestamp-with-timezone

我想知道为什么我与这篇帖子Post

截然不同
set timezone to 'UTC';

SELECT timestamptz '2012-03-05 17:00:00+0';  
Expected :2012-03-05 17:00:00+00
Got : 2012-03-05 22:30:00

SET timezone TO 'Europe/Berlin';

SELECT '2012-03-05 17:00:00+0'::timestamptz;  
Expected :  2012-03-05 18:00:00+01
Got: 2012-03-05 22:30:00



SELECT timestamptz '2012-03-05 18:00:00+1';
Expected : 2012-03-05 17:00:00+00
Got : 2012-03-05 22:30:00

2 个答案:

答案 0 :(得分:0)

我相信问题在于您如何设置时区。

您可以尝试将public class BasicAuthorizationFilter extends OncePerRequestFilter { private AuthenticationDetailsSource<HttpServletRequest, ?> authenticationDetailsSource = new WebAuthenticationDetailsSource(); @Autowired private AuthenticationManager authenticationManager; @Autowired private AuthenticationEntryPoint authenticationEntryPoint; private RememberMeServices rememberMeServices = new NullRememberMeServices(); @Override public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if(request.getHeader("X-API-USER-ID") == null || request.getHeader("Authorization") == null) { filterChain.doFilter(request, response); } final String uid = request.getHeader("X-API-USER-ID"); final String basicAuthorization = request.getHeader("Authorization"); if (basicAuthorization.toLowerCase().startsWith("basic")) { // TODO : something with username/password UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(uid, ""); token.setDetails(authenticationDetailsSource.buildDetails(request)); Authentication authResult = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(token); rememberMeServices.loginSuccess(request, response, authResult); } filterChain.doFilter(request, response); } @Override public void afterPropertiesSet() { Assert.notNull(authenticationManager, "An AuthenticationManager is required"); Assert.notNull(this.authenticationEntryPoint, "An AuthenticationEntryPoint is required"); } } 更改为SET timezone TO并查看是否可行吗?

您可以查看以下文档以获取更多帮助: https://www.postgresql.org/docs/9.1/datatype-datetime.html#DATATYPE-TIMEZONES

答案 1 :(得分:0)

实际上,我使用DBeaver作为DB IDE,我们需要在dbeaver.ini中进行一些调整,请参考post以获取更多见识