问题描述
我使用此URL在我的意大利网站中建立连接,但是,当我尝试从该网站执行某些插入操作时,日期仍然不正确. (应该是:01:24,但是是02:24)
I've this url to set up the connection in my Italy website, however, when i try to perform some insert action from the site, the date is still not right. (it should be for example: 01:24, but it is 02:24)
jdbc.url=jdbc:mysql://sql.example.com/database?autoReconnect=true&characterEncoding=UTF-8&sessionVariables=time_zone='Europe/Rome'
我是否需要添加其他任何参数以使其正常工作?是否有所有时区的完整列表?
Do I need to add any other params to make it work correctly?Is there a complete list of all timezones?
推荐答案
对不起,我没有您直接问题的答案.但是,我可以提出一些值得考虑的建议,可以完全避免数据库中的所有时区问题.如果可能的话,我建议仅使用BIGINT
字段来使用Java存储日期.您只需存储自纪元以来的毫秒数的long
,例如来自System.currentTimeMillis()
或Date.getTime()
.
Sorry I don't have the answer to your direct question. However I can suggest something worth considering that will avoid all time zone problems at the database entirely. If possible I recommend simply using BIGINT
fields for storing dates with Java. You just store the long
of the number of milliseconds since the epoch, e.g. from System.currentTimeMillis()
or Date.getTime()
.
然后,始终使用Java管理日期的时区解释,这擅长使用基于纪元的数字.直接在数据库中查询Java之外的日期确实需要更多的精力,但是它并不难,而且值得IMO使用:
Then interpretation of the time zone for a date is always managed in Java, which is good at using the epoch based number. It does make it a little more involved to directly query the database for a date outside of Java, however it's not too hard and tends to be worth it IMO:
SELECT FROM_UNIXTIME(date_field / 1000) FROM table;
这篇关于如何在JDBC中配置正确的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!