用Jdbc返回的日期是PDT时区 [英] Date returned with Jdbc is in PDT timezone

查看:61
本文介绍了用Jdbc返回的日期是PDT时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个独立脚本,该脚本使用Google Apps脚本JDBC对象在mySQL数据库中存储日期(日期类型字段).日期的时区为UTC.

I have written a stand-alone script that stores dates (Date type field) in a mySQL database using Google Apps Script JDBC object. The timezone of the dates is UTC.

我做一个选择所有日期的查询,例如:从 Table1

I do a query that selects all the dates, as an example: SELECT Date1 FROM Table1

当我使用GetObject(1)检索数据时,它将返回已设置PDT时区的Date对象.更准确地说,当我提示theDate.toString()时,它给了我:2012年7月30日星期一23:51:25 GMT + 0200(CEST)我注意到来自db的原始日期(2012-07-30 14:51:25)已被视为PDT,并转换为GMT + 2.

When I retrieve the data using GetObject(1), it returns a Date object having PDT timezone set. To be more precise, when I prompt theDate.toString(), it gives me: Mon Jul 30 2012 23:51:25 GMT+0200 (CEST) I notice that the original date (2012-07-30 14:51:25) from db has been considered as PDT and converted to GMT+2.

脚本时区不相关,并且设置为GMT + 1 ...

The Script timezone is not related and is set to GMT+1...

如何告诉JDBC数据库中的日期为UTC?

How can I tell to JDBC that the dates from the database are UTC?

谢谢

推荐答案

Some debugging done in Issue 1642 indicates that this is due to how JDBC works with MySQL, and the connection flags required to fix it currently can't be set in Apps Script.

为清楚起见,将JavaScript日期转换为字符串时显示的时区将始终是服务器的时区,在这种情况下为太平洋时间.使用 Utilities.formatDate 在特定时区显示日期.

To be clear through, the timezone shown when converting a JavaScript Date to a string will always be the timezone of the server, in this case Pacific Time. Use Utilities.formatDate to display a Date in a specific timezone.

这篇关于用Jdbc返回的日期是PDT时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆