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

查看:177
本文介绍了如何在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')

我该时区的所有大陆/首都组合,但不是确切的时区。例如,我得到:

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

Europe/Amsterdam
Europe/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的值。但是该值最终以 localtime结尾。您可以在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中的时区更改为欧洲/柏林,则显示时区; 将返回那个值,而不是 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中的时区设置为显式值,而不是默认的 localtime。

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天全站免登陆