UTC中的'NOW',没有时区 [英] 'NOW' in UTC with no timezone

查看:122
本文介绍了UTC中的'NOW',没有时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-----开始PGP签名消息-----

哈希:SHA1


嗨。


我正试着确定最好的方式来说''UTC当前时间

没有时区信息''。


我目前正在时区使用CURRENT_TIMESTAMP''UTC''并将

插入定义为TIMESTAMP WITHOUT TIME ZONE的列中,这些列似乎是
work。然而,PostgreSQL将其解析为更加令人困惑的时区(''UTC'':: text,(''now'':: text):: timestamp(6)with time zone )"

这是我生成的文档中出现的内容。


是否有任何魔术字符串,如''NOW'':: timestamp或CURRENT_TIMESTAMP

返回UTC时间?


- -

Stuart Bishop< st **** @ stuartbishop.net>
http://www.stuartbishop.net/

----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.2.4(GNU / Linux)

评论:使用GnuPG和Thunderbird - < a rel =nofollowhref =http://enigmail.mozdev.orgtarget =_ blank> http://enigmail.mozdev.org


iD8DBQFBa2XUAfqZj7rGN0oRAkLJAJ9vOWl1hDSbubKQUnCSvB Zg8nzvwACdFjvV

9vACiPZyhnXjlLZuTbGoUrs =

= gEL /

----- END PGP SIGNATURE -----


--------- ------------------(广播结束)---------------------------

提示2:您可以使用取消注册命令一次性取消所有列表

(发送&取消注册YourEmailAddressHere" ma*******@postgresql.org

解决方案

Stuart Bishop< st **** @ stuartbishop.net>写道:

我正在试图确定说'没有时区信息'的UTC当前时间的最佳方式。




这不是一个矛盾吗?


我想*也许你想要的是SET TIMEZONE =''UTC''然后

不要再担心了。但是,任何担心时区的人都会花费时间,而不是将时区存储在时间戳 - 无时区列中

可能需要重新考虑他的数据所代表的内容。 />
你真正想要存储的是什么,你想要怎么样?
它出现了什么?


问候,tom lane


---------------------------(广播结束)-------- -------------------

提示4:不要杀死-9''邮政局长


Tom Lane< tg *@sss.pgh.pa.us>写道:

Stuart Bishop< st **** @ stuartbishop.net>写道:

我正在努力确定说'没有时区信息'的当前UTC时间的最佳方式''。
不是吗这是一个矛盾吗?




如果您习惯于存储自纪元以来的秒数的Unix概念,那就不是了。

在该模型中,您存储的数量完全与时区无关。

但是任何担心时区而又将数据存储在
timestamp-without-time-zones列中的人可能需要重新考虑他的数据代表什么。




使用时间戳存储时区的SQL方法使得事情非常好

令人困惑。对于unix人来说,它需要一个与他们期望使用时间相反的时区。并且它意味着两个时间戳

代表相同的时间点可以有微妙的不同行为如果

它们存储在不同的时区。

我认为这个用户想要的是存储带时区的时间戳。并且

总是将时间存储在时区UTC中。这让他可以使用自纪元心理以来的时间来存储时间戳

,但是在他想要的任何时间内准确打印它们。


如果您将它们存储在没有时区的地方。然后postgres不会让你轻松

在非UTC时区显示它们。它认为它们是某个特定时间的特定时间,无论你在哪个时区,都会特定日期。


表示b $ b可能很有用。下午3点在您当地的时区这可以是

用于某些目的。例如,我用它代表到期特价的到期时间,因为它们会在您当地时间的特定日期到期

区域。如果您将打印输出从一个时区传输到另一个时区,则到期时间实际上会发生变化。在实践中,我会很高兴存储UTC

,然后使用AT TIMEZONE UTC进行打印。


-

greg

---------------------------(广播结束)------- --------------------

提示6:您是否搜索了我们的列表档案?

http://archives.postgresql.org

> > >我正在尝试确定最佳方式来说''UTC当前时间

没有时区信息'' 。



这不是一个矛盾吗?



如果你习惯了Unix的存储概念,那就不行了。自该纪元以来的秒数。
在该模型中,您存储的数量完全与时区无关。



但是一个是存储间隔,而不是存储一个点时间。


Karsten

-

GPG密钥ID E4071346 @ wwwkeys.pgp.net

E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

--------------------------- (广播结束)---------------------------

提示5:您查看了我们广泛的常见问题解答吗?

http://www.postgresql。组织/文档/常见问题/常见问题解答.html


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

I''m trying to determine the best way of saying ''The current time in UTC
with no time zone information''.

I''m currently using CURRENT_TIMESTAMP AT TIME ZONE ''UTC'' and inserting
into columns defined as TIMESTAMP WITHOUT TIME ZONE which appears to
work. However, PostgreSQL parses this into the much more confusing
"timezone(''UTC''::text, (''now''::text)::timestamp(6) with time zone)"
which is what is appearing on my generated documentation.

Is there any magic string like ''NOW''::timestamp or CURRENT_TIMESTAMP
which returns UTC time?

- --
Stuart Bishop <st****@stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBa2XUAfqZj7rGN0oRAkLJAJ9vOWl1hDSbubKQUnCSvB Zg8nzvwACdFjvV
9vACiPZyhnXjlLZuTbGoUrs=
=gEL/
-----END PGP SIGNATURE-----

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

解决方案

Stuart Bishop <st****@stuartbishop.net> writes:

I''m trying to determine the best way of saying ''The current time in UTC
with no time zone information''.



Isn''t that a contradiction in terms?

I *think* maybe what you want is to SET TIMEZONE = ''UTC'' and then
stop worrying about it. But anyone who is worried about timezones
and yet is storing his data in timestamp-without-time-zone columns
probably needs to reconsider exactly what his data represents.
What is it that you actually want to store, and how do you want
it presented?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don''t ''kill -9'' the postmaster


Tom Lane <tg*@sss.pgh.pa.us> writes:

Stuart Bishop <st****@stuartbishop.net> writes:

I''m trying to determine the best way of saying ''The current time in UTC
with no time zone information''.
Isn''t that a contradiction in terms?



Not if you''re used to the Unix concept of storing "seconds since the epoch".
In that model the quantity you''re storing is entirely time zone agnostic.
But anyone who is worried about timezones and yet is storing his data in
timestamp-without-time-zone columns probably needs to reconsider exactly
what his data represents.



The SQL approach of storing a time zone with the timestamp makes things very
confusing. For unix people it requires a time zone in precisely the opposite
circumstances from when they expect to use one. And It means two timestamps
representing the same point in time can have subtly different behaviours if
they''re stored with different time zones.

I think what this user wants is to store a "timestamp with time zone" and
always store his time with the time zone "UTC". That lets him store timestamps
using the time since epoch mentality, but print them accurately in whatever
time zone he wants.

If you stored them "without time zone" then postgres wouldn''t let you easily
display them in non-UTC time zones. It considers them to be a particular time
of a particular day in whatever time zone you''re in.

It could be useful to represent "3pm in your local time zone" which can be
useful for some purposes. For example, I''m using it to represent the expiry
time of specials, since they expire on a particular date in your local time
zone. If you transport the printout from one time zone to another the expiry
time actually changes. In practice I would have been just as happy storing UTC
and then printing using "AT TIMEZONE UTC".

--
greg
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


> > > I''m trying to determine the best way of saying ''The current time in UTC

with no time zone information''.



Isn''t that a contradiction in terms?



Not if you''re used to the Unix concept of storing "seconds since the epoch".
In that model the quantity you''re storing is entirely time zone agnostic.


But then one is storing an interval, not a point in time.

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


这篇关于UTC中的'NOW',没有时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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