oracle裏關於日期和時間考慮的是比較全面的,不僅支持TimeZone而且也包含了Daylight Saving Time,下面列出其中一些常用的關於日期時間的函數:
from_tz: 用於轉換一個timestamp變爲timestamp with time zone類型
select from_tz(timestamp '2000-06-30 18:30:00','-5:00') from dual;
to_timestamp:轉換字符串格式爲timestamp格式
to_timestamp_tz:類似to_timestamp,並添加了time zone信息
select to_timestamp('2000-06-30 18:30:00','yyyy-mm-dd hh24:mi:ss'),
to_timestamp_tz('2000-06-30 18:30:00 -06:00','yyyy-mm-dd hh24:mi:ss tzh:tzm')from dual;
to_yminterval:轉換字符串爲yminterval格式
select to_date('2000-06-30','yyyy-mm-dd')+to_yminterval('02-01') from dual;
tz_offset:獲取時區相對於utc的時間偏差
select tz_offset('Asia/Tokyo') from dual;
current_date:獲取當前日期
current_timestamp:獲取當前時間(包括時區並根據客戶端tz設置顯示)
localtimestamp:當前時間,但不顯示時區
dbtimezone:數據庫時區
sessiontimezone:當前session的時區
extract:從日期或時間中抽取指定字段值
select extract(year from to_date('2010-06-30','yyyy-mm-dd')) from dual;