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时钟(系 ...
随机推荐
- android apk 防止反编译技术第二篇-运行时修改字节码
上一篇我们讲了apk防止反编译技术中的加壳技术,如果有不明白的可以查看我的上一篇博客http://my.oschina.net/u/2323218/blog/393372.接下来我们将介绍另一种防止a ...
- c# 鼠标点击控件即拖动窗体
在编程中,有时打开的窗体没有边框,但是我们仍然想在鼠标放在窗体上就能拖动窗体,这样我们只需要以窗体中的一个控件为参考,我们在这里以panel为例子: public class PanelNew : P ...
- phpstrom添加monokai-sublime主题
phpstrom默认的主题看起来不是特别舒服,sublime的主题却相当养眼,搜索之后,大为惊喜. 下载地址:https://github.com/sumiaowen/jetbrains-monoka ...
- 在多台手机上批量安装apk
1.手机要打开adb调试 2.该程序可以实现台android手机的多个apk批量安装 1.getSeriaoNum.py模块,该模块获取已连接手机的序列号 import os import threa ...
- 扩展thinkphp5的redis类方法
笔者在开发时发现,thinkphp5的自带redis类方法,只有简单的读取缓存.写入缓存的基本方法,远不能满足我们业务的需求.redis本身支持五种数据类型,string(字符串).hash(哈希). ...
- python中出现 IndentationError:unindent does not match any outer indentation level
python中出现IndentationError:unindent does not match any outer indentation level 今天在网上copy的一段代码,代码很简单,每 ...
- opengl1
OpenGL Programming Guide Programming Guide > Chapter 1 Chapter 1 Introduction to OpenGL Chapter O ...
- 洛谷P1005 矩阵取数游戏
P1005 矩阵取数游戏 题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次 ...
- [Xcode 实际操作]六、媒体与动画-(11)UIView视图卷曲动画的制作
目录:[Swift]Xcode实际操作 本文将演示UIView视图卷曲动画的制作. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit cla ...
- wampserver2.5局域网公网IP访问配置
wampserver2.5集成环境的安装和使用就不多说了,网上有很多教材.安装好后找到apache的配置文件httpd.conf.默认位置是: swap安装目录\wamp\bin\apache\apa ...