天天看点

PostgreSQL Oracle兼容性之 - NEW_TIME , SYS_EXTRACT_UTC

如何将一个时区的本地时间,转换为另一个时区的本地时间?

在oracle中可以使用new_time这个函数实现这个目的。

new_time(ts, tz1, tz2)

new_time returns the date and time in time zone timezone2 when date and time in time zone timezone1 are date.

the arguments timezone1 and timezone2 can be any of these text strings:

例子

另外oracle还有一个函数sys_extract_utc,是将一个timestamptz转换成utc时区的本地时间

<a href="https://docs.oracle.com/cd/b12037_01/server.101/b10759/functions152.htm">https://docs.oracle.com/cd/b12037_01/server.101/b10759/functions152.htm</a>

了解功能之后,pg就很容易实现new_time的函数了。

postgresql的时区列表。

验证对应oracle的例子

自定义函数如下

验证

<a href="https://www.postgresql.org/docs/7.2/static/timezones.html">https://www.postgresql.org/docs/7.2/static/timezones.html</a>

<a href="https://docs.oracle.com/cd/b19306_01/server.102/b14200/functions092.htm">https://docs.oracle.com/cd/b19306_01/server.102/b14200/functions092.htm</a>

<a href="http://info.flagcounter.com/h9v1">count</a>