在时区之间的分钟数之间获得差异 [英] Get difference in minutes between times with timezone
本文介绍了在时区之间的分钟数之间获得差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在PostgreSQL中有一个表:
I have a table in PostgreSQL:
CREATE TABLE tableA
(
time_A time with timezone
);
如何获取 now()$ c之间的分钟差$ c>和
time_A
?
推荐答案
首先,类型 timetz
被设计破坏了,不建议使用:
First off, the type timetz
is broken by the design and its use is discouraged:
- Postgres time with time zone equality
如果要包括时区,请使用 timestamptz
。但请注意,实际时区未明确存储:
If you want to include the time zone, use timestamptz
instead. But be awaare that the actual time zone is not stored explicitly:
- Time zone storage in data type "timestamp with time zone"
Postgres中时间戳/时区处理的详细信息:
Details for timestamp / time zone handling in Postgres:
- < a href = https://stackoverflow.com/questions/9571392/ignoring-timezones-altogether-in-rails-and-postgresql/9576170#9576170>完全忽略Rails和PostgreSQL中的时区
- Ignoring timezones altogether in Rails and PostgreSQL
假设时间
SELECT EXTRACT('epoch' FROM now()::time - time_a) / 60 AS minutes
FROM tablea;
-
now()
返回timestamptz
,该值会自动针对当前时区进行调整。转换为时间
时,您将获得本地时间。
- now()和current_timestamp
now()
returnstimestamptz
, which is adjusted for the current time zone automatically. You get the local time when casting totime
.- Difference between now() and current_timestamp
这篇关于在时区之间的分钟数之间获得差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文