Postgresql 獲取當前時間


 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)'  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM