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;