On occasion giving a date time with a time zone, we want to get the date time under another time zone, how to do it? Here gives a solution:
FUNCTION fun_exchange_timestamp_tz(pv_timestamp TIMESTAMP,
pv_from_tz VARCHAR2,
pv_to_tz VARCHAR2) RETURN TIMESTAMP
WITH TIME ZONE AS
BEGIN
IF pv_timestamp IS NULL
THEN
RETURN NULL;
END IF;
RETURN from_tz(pv_timestamp, pv_from_tz) at TIME ZONE pv_to_tz;
END fun_exchange_timestamp_tz;
/*exchange the date from one time zone to other time zone.*/
FUNCTION fun_exchange_date_tz(pv_date DATE,
pv_from_tz VARCHAR2,
pv_to_tz VARCHAR2) RETURN DATE AS
BEGIN
RETURN fun_exchange_timestamp_tz(CAST(pv_date AS TIMESTAMP),
pv_from_tz,
pv_to_tz);
END;
We can use those functions as below:
select fun_exchange_timestamp_tz(sysdate,'Asia/Shanghai','GMT') from dual;
select fun_exchange_date_tz(sysdate,'Asia/Shanghai','GMT') from dual;
These sqls convert sysdate from time zone 'Asia/Shanghai' time zone ‘GMT’.
分享到:
相关推荐
3. `timestamp with time zone`:这是一个特殊的时间戳类型,包含了时区信息。在转换和比较日期时间时,考虑时区差异非常重要。 4. `sec_to_time`:此函数将秒数转换为时间格式,例如`select sec_to_time(3605)`会...
HP Vertica supports date/time literals with time zone values and day-of-the-week and month names. - **Interval Values**: Interval values represent durations and can be specified using interval ...
9.1.1. Always Set a Default Timezone 9.1.2. Why Use Zend_Date? 9.2. 操作理论 9.2.1. 内部(Internals) 9.3. Basic Methods 9.3.1. The current date 9.3.2. Zend_Date by Example 9.3.2.1. Ouput a Date...
The directory from the --with-config-file-path compile time option, or the ; Windows directory (C:\windows or C:\winnt) ; See the PHP docs for more specific information. ; ...
- `timestamp` 映射到 `timestamp with time zone` 对于日期和时间操作,可以使用 PostgreSQL 内置函数来实现 SQL Server 中的功能,例如: - `getdate()` 可以通过 `now()` 替换 - `dateadd()` 可以通过 `now() +...
SELECT DBTIMEZONE db_timezone FROM dual; ``` **结果**: ``` DB_TIMEZONE -------------- America/New_York ``` 以上是Oracle 11g中常用的函数的部分介绍,包括了数学函数、日期函数、字符串函数等类别。这些函数...
Python参考手册,官方正式版参考手册,chm版。以下摘取部分内容:Navigation index modules | next | Python » 3.6.5 Documentation » Python Documentation contents What’s New in Python ...PEP 343: The ‘with...
说明: 指定一对值 (UTC,TZD), 设置 TIME WITH TIME ZONE 数据类型的默认值, 该数据类型包含 HOUR, MINUTE, SECOND, TIMEZONE_HOUR 和 TIMEZONE_MINUTE 这几个日期时间字段。UTC 是世界时而 TZD 是当地时区。 语法: ...