highgo=# select now();
now
-------------------------------
2017-06-21 13:52:39.407304+08
(1 row)
highgo=# select current_timestamp;
now
-------------------------------
2017-06-21 13:53:07.656107+08
(1 row)
highgo=# select transaction_timestamp();
transaction_timestamp
-------------------------------
2017-06-21 13:53:24.948411+08
(1 row)
以上三个函数是等效的
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
highgo=# select localtime;
time
----------------
13:53:36.46901
(1 row)
highgo=# select localtimestamp;
timestamp
----------------------------
2017-06-21 13:53:39.921847
(1 row)
highgo=# select current_time;
timetz
--------------------
13:53:56.716011+08
(1 row)
highgo=# select current_date;
date
------------
2017-06-21
(1 row)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
以下为三个返回实时时间的函数:
highgo=# select statement_timestamp();
statement_timestamp
-------------------------------
2017-06-21 13:57:27.246504+08
(1 row)
highgo=# select clock_timestamp();
clock_timestamp
-------------------------------
2017-06-21 13:57:35.847353+08
(1 row)
highgo=# select timeofday();
timeofday
-------------------------------------
Wed Jun 21 13:57:49.782139 2017 CST
(1 row)
now
-------------------------------
2017-06-21 13:52:39.407304+08
(1 row)
highgo=# select current_timestamp;
now
-------------------------------
2017-06-21 13:53:07.656107+08
(1 row)
highgo=# select transaction_timestamp();
transaction_timestamp
-------------------------------
2017-06-21 13:53:24.948411+08
(1 row)
以上三个函数是等效的
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
highgo=# select localtime;
time
----------------
13:53:36.46901
(1 row)
highgo=# select localtimestamp;
timestamp
----------------------------
2017-06-21 13:53:39.921847
(1 row)
highgo=# select current_time;
timetz
--------------------
13:53:56.716011+08
(1 row)
highgo=# select current_date;
date
------------
2017-06-21
(1 row)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
以下为三个返回实时时间的函数:
highgo=# select statement_timestamp();
statement_timestamp
-------------------------------
2017-06-21 13:57:27.246504+08
(1 row)
highgo=# select clock_timestamp();
clock_timestamp
-------------------------------
2017-06-21 13:57:35.847353+08
(1 row)
highgo=# select timeofday();
timeofday
-------------------------------------
Wed Jun 21 13:57:49.782139 2017 CST
(1 row)

本文介绍了PostgreSQL(HighGo DB,简称PG)中获取当前时间与日期的多个函数,包括now()、current_timestamp、transaction_timestamp、localtime、localtimestamp、current_time、current_date、statement_timestamp、clock_timestamp和timeofday。这些函数在数据库操作中用于获取系统当前的时间和日期信息。
702

被折叠的 条评论
为什么被折叠?



