Postgresql 当中有四种方式获取当前时间

来源:互联网 发布:mac 无法开机无法充电 编辑:程序博客网 时间:2024/06/05 15:20
 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)'
1 0