如何在 Postgres 9.3 中获取当前时区名称? [英] How do I get the current timezone name in Postgres 9.3?

查看:27
本文介绍了如何在 Postgres 9.3 中获取当前时区名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取当前时区名称.我已经实现的是通过以下方式获取 utc_offset/时区缩写:

I want to get the current timezone name. What I already achieved is to get the utc_offset / the timezone abbreviation via:

SELECT * FROM pg_timezone_names WHERE abbrev = current_setting('TIMEZONE')

这给了我这个时区的所有大陆/首都组合,但不是确切的 timezone.例如我得到:

This gives me all Continent / Capital combinations for this timezone but not the exact timezone. For example I get:

Europe/Amsterdam
Europe/Berlin

服务器位于 Berlin,我想获取服务器的时区名称.

The server is in Berlin and I want to get the timezone name of the server.

CET 的问题是它始终是 UTC+01:00 并且不考虑 DST iirc.

The problem I have with CET that it is always UTC+01:00 and does not account for DST iirc.

推荐答案

我认为在最一般的情况下单独使用 PostgreSQL 是不可能的.安装 PostgreSQL 时,您选择了一个时区.我很确定默认是使用操作系统的时区.这通常会在 postgresql.conf 中反映为参数timezone"的值.但该值最终为本地时间".您可以使用 SQL 语句查看此设置.

I don't think this is possible using PostgreSQL alone in the most general case. When you install PostgreSQL, you pick a time zone. I'm pretty sure the default is to use the operating system's timezone. That will usually be reflected in postgresql.conf as the value of the parameter "timezone". But the value ends up as "localtime". You can see this setting with the SQL statement.

show timezone;

但是,如果您将 postgresql.conf 中的时区更改为Europe/Berlin"之类的内容,则 show timezone; 将返回 那个 值而不是localtime".

But if you change the timezone in postgresql.conf to something like "Europe/Berlin", then show timezone; will return that value instead of "localtime".

所以我认为您的解决方案将涉及将 postgresql.conf 中的时区"设置为显式值,而不是默认的本地时间".

So I think your solution will involve setting "timezone" in postgresql.conf to an explicit value rather than the default "localtime".

这篇关于如何在 Postgres 9.3 中获取当前时区名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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