PostgreSQL时间存储形式与格式化

1 存储形式

1.1 时间戳形式

 create_time | timestamp with time zone |           | not null | 
2018-08-28 17:12:42.453297+08

1.2 大整数形式(Unix格式)

 create_time   | bigint                   |           | not null | 0
1534325947

2 格式转换

2.1 时间戳转Unix

 select extract(epoch from create_time) from tb;

2.2 Unix 转时间戳

 select to_timestamp(create_time) from tb;

2.3 时间戳转字符串

select to_char(create_time, 'YYYY-MM-DD  HH24:MI:SS ') from tb

参考:https://blog.csdn.net/aleefang/article/details/78679402

转载自:https://blog.csdn.net/idwtwt/article/details/82222147

You may also like...