gpt4 book ai didi

Rails query timestamp delta from GMT(来自GMT的Rails查询时间戳增量)

转载 作者:bug小助手 更新时间:2023-10-28 20:41:00 25 4
gpt4 key购买 nike



Time stamps are saved, via postgresql, as: "1991-12-02 01:11:00.000000000 +0100".

时间戳通过PostgreSQL保存为:“1991-12-02 01:11:00.000000000+0100”。


However, there are a number of records that were created with elements of data that are off and the console returns timezone adjusments as

但是,有许多记录是使用关闭的数据元素创建的,并且控制台将时区调整返回为


 LMT +00:49

There is no clue why an offset ended up being +00:49...

不知道为什么偏移量最终是+00:49...


How can these records be queried and subsequently adjusted so that the time is the existing value + 1 hour AND showing the timezone as CET +0100 ?

如何查询这些记录并随后对其进行调整,以使时间为现有值+1小时并将时区显示为CET+0100?


The attribute is of datatype datetime, whereas LMT is GMT + 0100

该属性的数据类型为DATETIME,而LMT为GMT+0100


更多回答

What is the data type (timestamp without time zone or timestamp with time zone). BTW Postgres does not store timestamps in any year:month:day... format; they are stored in an internal structure. Further the UTC offset/Timezone is not stored, it is retrieved from the server. LMT is GMT?

数据类型是什么(不带时区的时间戳或带时区的时间戳)。顺便说一句,Postgres不存储任何年份的时间戳:月:日...格式;它们存储在内部结构中。此外,不存储UTC偏移量/时区,而是从服务器检索它。LMT是GMT吗?

question updated

问题已更新

Postgres does not have a data type datetime must be a Rails datatype. Sign-in directly to your database from a console and enter command \d+ tablename. It will show the complete table description. Post that description, as text - not an image.

Postgres没有数据类型,DateTime必须是Rails数据类型。从控制台直接登录到您的数据库,然后输入命令\d+表名。它将显示完整的表描述。将描述以文本形式发布,而不是图像。

@Belayer The rails schema type datetime corresponds to timestamp in Postgres. The OP here is falling for the age old trap of thinking that a timestamp and its original timezone can be stored in a single column.

@Belayer Rails模式类型DateTime对应于Postgres中的时间戳。这里的操作正在陷入一个古老的陷阱,即认为时间戳及其原始时区可以存储在单个列中。

PostgreSQL (with the default config) does not know a timezone abbreviated 'LMT'. Either you have a weird compilation/configuration of PostgreSQL. or this is something Ruby is foisting onto you.

PostgreSQL(使用默认配置)不知道缩写为'LMT'的时区。要么你有一个奇怪的PostgreSQL编译/配置。要么这是露比强加给你的

优秀答案推荐

You can't actually store a timestamp and its original timezone in a single column.*

您不能在单个列中实际存储时间戳及其原始时区。*


This is a pretty common source of confusion but Postgres (and many other databases) actually store dates/time as an internal number-y type. In previous versions the default varied between a double precision float or a 8-bit integer (it's not stated in the current version of the docs).

这是一个非常常见的混淆来源,但是postgres(和许多其他数据库)实际上将日期/时间存储为内部数字y类型。在以前的版本中,缺省值在双精度浮点型或8位整型之间变化(当前版本的文档中没有说明)。


Neither time, date, timestamp or timestamp with zone (despite the confusion caused by the name) store any information about the original timezone - it merely changes how the input is coerced into the database timezone or UTC.

TIME、DATE、TIMESTAMP或TIMESTAMP WITH ZONE(尽管名称引起混淆)都不会存储有关原始时区的任何信息--它只是改变了强制输入到数据库时区或UTC的方式。


To be able to implement this feature you'll need to store the original timezone in a separate column and then convert the stored time into the original timezone. Depending on your needs this can either be done in Rails or in Postgres with AT TIME ZONE.

要实现此功能,您需要将原始时区存储在单独的列中,然后将存储的时间转换为原始时区。根据您的需要,这可以在Rails中完成,也可以在带有AT时区的Postgres中完成。


See:

请参见:



更多回答

* Of course its possible to use a something like a text column or that someone has written a Postgres extension with a custom type that does this.

*当然,可以使用文本列之类的东西,或者有人编写了一个带有定制类型的postgres扩展来实现这一点。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com