Postgresql 當中有四種方式獲取當前時間。
一:now()
通過now()獲取的時間是最完整的時間,包括時區,秒也保留到了6位小數。
select now();
得到的結果如下
'2014-12-24 09:28:31.545145+08'
二:current_timestamp效果是和now()一樣的。
三:current_time
只顯示當前的時間,不包括日期
select current_time;
得到的結果如下
'09:32:02.039705+08'
四:current_date
只顯示當前的日期,不包括小時等信息
select current_date;
得到的結果如下
'2014-12-24'
我們還可以控制now()的返回格式,如下
select now()::timestamp(0)without time zone;(current_timestamp 是和now()一樣的)
時間的計算方式,如下
select now() + interval '10 min/year/month/day/hour/sec/ (1 year 1 month 1 day 1 hour 1 min 1 sec)'