Postgresql 日期和时间类型
2017-12-18 15:01
330 查看
timestamp with[out] time zone 日期时间(时区) time with[out] time zone 只用于一日内的时间(时区) 可以精确到毫秒。MySQL只能到秒。 默认都不会显示时区,需要显示的指定with time zone。 highgo=# select time '120900'; time ---------- 12:09:00 (1 row) highgo=# select time '120900 PST'; time ---------- 12:09:00 (1 row) highgo=# select time WITH time zone '120900 PST'; timetz ------------- 12:09:00-08 (1 row) 在输入日期时,有很多种格式。有时候需要确定datestyle。 highgo=# create table t(date date); CREATE TABLE highgo=# insert into t values (date '12-18-2010'); INSERT 0 1 highgo=# select * from t; date ------------ 2010-12-18 (1 row) highgo=# show datestyle; DateStyle ----------- ISO, MDY (1 row) highgo=# set datestyle = 'YMD'; SET highgo=# insert into t values (date '2010-12-19'); INSERT 0 1 highgo=# select * from t; date ------------ 2010-12-18 2010-12-19 (2 rows) 注: 建议使用 2017-12-18 这种方式输入日期。任何方式下都是2017年12月18日。 PostgreSQL 提供可许多返回当前日期和时间的函数。 部分函数按照当前事务的开始时刻返回结果: CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP CURRENT_TIME(precision) LOCALTIME LOCALTIMESTAMP now() transaction_timestamp() 感觉这个描述更符合实际情况 另外部分函数返回实时时间值,在事务中也会随时间变化。 statement_timestamp() clock_timestamp() timeofday() 返回的是text字符串 在同一个事务中,和now()同类型的函数不会变化,和statement_timestamp()同类型的函数则相反。 highgo=# begin; BEGIN highgo=# select now(); now ------------------------------- 2017-12-18 12:18:32.263891+08 (1 row) highgo=# select now(); now ------------------------------- 2017-12-18 12:18:32.263891+08 (1 row) highgo=# select statement_timestamp(); statement_timestamp ------------------------------- 2017-12-18 12:19:15.463267+08 (1 row) highgo=# select statement_timestamp(); statement_timestamp ------------------------------- 2017-12-18 12:19:18.975693+08 (1 row) highgo=# commit; COMMIT By 天蝎座
相关文章推荐
- PostgreSQL学习篇9.9 日期/时间类型
- postgresql 日期类型处理实践
- 6.3 Java时间和日期类型的Hibernate映射
- JavaScript字符串类型时间转换为日期类型比较
- (转载)C#语言之“string格式的日期时间字符串转为DateTime类型”的方法
- MySQL日期数据类型、时间类型使用总结
- MySQL日期和时间类型
- java中时间类型转化以及由已知日期得到所需日期
- C#日期时间类型格式化大全集 C#DateTime 类型格式化大全集
- PHPExcel对于Excel中日期和时间类型的处理
- Oracle时间运算与日期类型转换
- SQL Server中日期时间类型字段只取年月日
- hibernate Java 时间和日期类型的 Hibernate 映射
- MySQL中日期与时间类型
- MySQL数据库中有字段类型是日期、时间的插入语句的写法处理
- MySQL日期数据类型、时间类型使用总结
- Mysql 建表时,日期时间类型选择
- MySQL基础教程17-Mysql数据类型-日期时间
- JAVA将十位时间戳格式化为日期Date类型
- ORACLE 日期时间数据类型与时间间隔数据类型讲解