简体   繁体   English

不同区域的日期/时间问题

[英]Date/time issue with different zone

Spring boot application i set globally time zone UTC. Spring Boot应用程序我设置了全球时区UTC。 so that client (Angular) they are displaying based on user time zone that is correct working. 以便他们根据正确的用户时区显示客户端(角度)。 But the problem is we are searching the record based on changed date. 但是问题是我们正在根据更改的日期搜索记录。 How to solve that issue? 如何解决这个问题?

Example: 例:

  1. create one record(submission date) in db that is UTC suppose 30/10/2018 : 7:30:45 在UTC中创建一个记录(提交日期)为UTC,假设30/10/2018:7:30:45
  2. now i return the response to client that date is(submission) 30/10/2018 then after in anguar.js app they are converting based on user time zone just assume in US time Zone it will display (submission date)29/10/2018 , 现在我将日期为(提交)30/10/2018的回复返回给客户端,然后在anguar.js应用中,他们基于用户时区进行转换,只是假设它将在美国时区显示(提交日期)29/10 / 2018年
  3. So how can I solved that issue when user search the record based on submission date (29/10/2018) 所以当用户根据提交日期搜索记录时,如何解决该问题(29/10/2018)
  4. in DB actual date is 30/10/2018 but in client app they are searching based on client date 29/10/2018 在数据库中的实际日期是30/10/2018,但是在客户端应用中,它们基于客户端日期29/10/2018进行搜索

It is their(Front-end developer's) responsibility to send UTC date to server and server will return the results based on UTC only and then they can convert dates in user's timezone. 将UTC日期发送到服务器是他们(前端开发人员)的责任,服务器将仅基于UTC返回结果,然后他们可以在用户的​​时区中转换日期。

So the conclusion is the server will be handling only one timezone which is UTC. 因此结论是服务器将仅处理一个时区,即UTC。

Ask angular developer to convert the date into UTC and send it to server. 要求Angular开发人员将日期转换为UTC并将其发送到服务器。

@Jack ...尝试一下它将解决

spring.datasource.url=jdbc:mysql://localhost:3306/veta?useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC

I fixed above issue using mysql query 我使用mysql查询修复了上述问题

In MySQL the CONVERT_TZ() returns a resulting value after converting a datetime value from a time zone specified as the second argument to the time zone specified as the third argument. 在MySQL中,CONVERT_TZ()在将datetime值从指定为第二个参数的时区转换为指定为第三个参数的时区后,返回结果值。 This function returns NULL when the arguments are invalid. 当参数无效时,此函数返回NULL。

CONVERT_TZ (dt, from_tz,to_tz)

Name        Description
dt          A datetime.
from_tz     A time zone which will be converted to to_tz.
to_tz      A time zone in which the from_tz will convert.

enter image description here 在此处输入图片说明

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

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