PostgreSQL: epoch 新纪元时间的使用
新纪元时间 Epoch 是以 1970-01-01 00:00:00 UTC 为标准的时间,将目标时间与 1970-01-01 00:00:00
时间的差值以秒来计算 ,单位是秒,可以是负值; 有些应用会将时间存储成epoch 时间形式,以提高读取效率,
下面演示下 pg 中 epoch 时间的使用换算方法。
--1 将 time stamp 时间转换成 epoch 时间
francs=> select extract(epoch from timestamp without time zone '1970-01-01 01:00:00');
date_part
-----------
3600
(1 row)
francs=> select extract(epoch from timestamp without time zone '1970-01-01 02:00:00');
date_part
-----------
7200
(1 row)
francs=> select extract(epoch from interval '+1 hours');
date_part
-----------
3600
(1 row)
francs=> select extract(epoch from interval '-1 hours');
date_part
-----------
-3600
(1 row)
--2 将epoch 时间转换成 time stamp 时间
francs=> select timestamp without time zone 'epoch' + 3600 * interval '1 second';
?column?
---------------------
1970-01-01 01:00:00
(1 row)
francs=> select timestamp without time zone 'epoch' + 7200 * interval '1 second';
?column?
---------------------
1970-01-01 02:00:00
(1 row)
--3 手册上关于 epoch 的解释
For date and timestamp values, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative);
for interval values, the total number of seconds in the interval
epoch
For date and timestamp values, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative); for interval values, the total number of seconds in the interval
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
Result: 982384720.12 SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
Result: 442800
Here is how you can convert an epoch value back to a time stamp:
SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 982384720.12 * INTERVAL '1 second'; http://www.postgresql.org/docs/9.1/static/functions-datetime.html
PostgreSQL: epoch 新纪元时间的使用的更多相关文章
- PostgreSQL - 怎么将时间转换成秒
保留原来的毫秒值 select extract(epoch from '03:21:06.678'::time); 这个extract(epoch from )函数得到的是时间是秒单位,如果需要毫秒值 ...
- PostgreSQL查询当前时间的时间戳
一.问题 使用PostgreSQL获取当前系统时间戳.众所周知,在MySQL中是这样的: select UNIX_TIMESTAMP(NOW()) 二.解决方案 (1)精确到秒 " (2)精 ...
- PostgreSQL中的 时间格式转化常识
下面的SQL文查询结果是 "2018-08-20 10:09:10.815125",并且返回类型可以当String处理.返回json等都方便使用. SQL> SELECT t ...
- 【PostgreSQL】PostGreSQL数据库,时间数据类型
---"17:10:13.236"time without time zone:时:分:秒.毫秒 ---"17:10:13.236+08"time with t ...
- PostgreSQL中的时间操作总结
取当前日期的函数: (1) 取当前时间:select now() (2) 取当前时间的日期: select current_date (3) 取当前具体时间(不含日 ...
- PostgreSQL的时间/日期函数使用
PostgreSQL的常用时间函数使用整理如下: 一.获取系统时间函数 1.1 获取当前完整时间 select now(); david=# select now(); now ----------- ...
- [转] PostgreSQL的时间/日期函数使用
PS:http://blog.csdn.net/love_rongrong/article/details/6712883 字符串模糊比较 日期类型的模糊查询是不能直接进行的,要先转换成字符串然后再查 ...
- [转帖]PostgreSQL的时间/日期函数使用
PostgreSQL的时间/日期函数使用 https://www.cnblogs.com/mchina/archive/2013/04/15/3010418.html 这个博客的 文章目录比上一个好十 ...
- linux概念之时间与时区
http://www.cnblogs.com/liuyou/archive/2012/07/29/2614338.html Linux时间基准 以上我们了解了RTC(实时时钟.硬件时钟)和OS时钟(系 ...
随机推荐
- 利用java在服务器和客服端建立连接,进行通讯(代码实例)
客服端代码:有注释 package javanet; import java.io.IOException; import java.io.InputStream; import java.io.Ou ...
- linux下使用c判断文件夹是否为空的小程序
自己写了一个 判断文件夹是否为空的小代码 //文件夹操作相关的函数的帮助$: man 3 readdir #include <stdio.h> #include <sys/types ...
- JS Guid生成
function numToGuid(uid) { var str = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; var l = uid.to ...
- 为什么要用babel-polyfill
1.为什么要用babel-polyfill Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,比如 Iterator.Generator.Set.Maps.Prox ...
- 关于c语言中的字符串的问题
静态数组,动态数组,链表是c语言中处理存储数据最基本的三种方式. 1.静态数组,你先定好大小,直接赋值即可,不要超过定义的长度. 2.动态分配数组,在执行的时候,输入要分的内存大小,然后p=(vo ...
- JS中substr与substring的区别
js中substr和substring都是截取字符串中子串,非常相近,可以有一个或两个参数. 语法:substr(start [,length]) 第一个字符的索引是0,start必选 length可 ...
- 管理docker容器
如果在容器中启动sshd,存在开销和攻击面增大的问题.同时也违反了Docker所倡导的一个容器一个进程的原则. docker attach 37d61466c69e \\注意:如果在stdin中exi ...
- JSON解析器之jackson json数据和java对象转换
- 字符串前面u,r,b
u :代表是对字符串进行unicode编码. 一般英文字符在使用各种编码下, 基本都可以正常解析, 所以一般不带u:py3当对字符串进行操作的时候,默认使用Unicode编码 r/R:非转义的原始字符 ...
- 第一个Three.js程序——加入相机