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;

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