PostgreSQL獲取當前時間的方式

PostgreSQL 當中有四種方式獲取當前時間。

1. now()

通過 now() 獲取的時間是最完整的時間,包括時區,秒也保留到了6位小數

select now();

得到結果:'2014-12-24 09:28:31.545145+08'

2. current_timestamp 效果是和 now() 一樣的。

select current_timestamp;

得到結果:'2019-03-07 15:47:21.650475+08'

3. current_time

只顯示當前的時間,不包括日期

select current_time;

得到結果:'09:32:02.039705+08'

4. current_date

只顯示當前的日期,不包括小時等信息

select current_date;

得到結果:'2014-12-24'

還可以控制 now() 的返回格式,如下

select now()::timestamp(0)without time zone;

select current_timestamp::timestamp(0)without time zone;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章