日期、字符串、时间戳之间的互相转换
来源:互联网 发布:航天证券交易软件 编辑:程序博客网 时间:2024/05/01 14:33
日期、字符串、时间戳之间的互相转换,虽然常用但是几乎每次使用时候都喜欢去搜索一下用法;本文将作为一个笔记,整理一下三者之间的 转换(即:date转字符串、date转时间戳、字符串转date、字符串转时间戳、时间戳转date,时间戳转字符串)用法,方便日后查看;
涉及的函数
date_format(date, format) 函数,MySQL日期格式化函数date_format()
unix_timestamp() 函数
str_to_date(str, format) 函数
from_unixtime(unix_timestamp, format) 函数,MySQL时间戳格式化函数from_unixtime
时间转字符串
- select date_format(now(), '%Y-%m-%d');
- #结果:2016-01-05
时间转时间戳
- select unix_timestamp(now());
- #结果:1452001082
字符串转时间
- select str_to_date('2016-01-02', '%Y-%m-%d %H');
- #结果:2016-01-02 00:00:00
字符串转时间戳
- select unix_timestamp('2016-01-02');
- #结果:1451664000
时间戳转时间
- select from_unixtime(1451997924);
- #结果:2016-01-05 20:45:24
时间戳转字符串
- select from_unixtime(1451997924,'%Y-%d');
- //结果:2016-01-05 20:45:24
附表
MySQL日期格式化(format)取值范围。
阅读全文
0 0
- 日期、字符串、时间戳之间的互相转换
- 时间戳和日期的互相转换
- oracle 时间和字符串之间的互相转换
- 日期时间与字符串互相转换
- 时间戳标准日期之间的转换
- 日期和unix时间戳的互相转换
- js时间戳、日期格式 互相转换
- 时间戳和日期互相转换
- 字符串与数字之间的互相转换
- 字符串与数字之间的互相转换
- 字符串与数字之间的互相转换
- 字符串和数字之间的互相转换
- 日期字符串之间的转换
- 时间戳与字符串之间的转换
- python中时间、日期、时间戳之间的转换
- js字符串和时间戳互相转换
- 日期、时间戳互相转换、日期之差
- Python时间,日期,时间戳之间转换
- 关于web.XML文件的welcome-file设置成 .do/.action问题
- Matlab 图像处理总结
- The last packet successfully received from the server was 30,516,920 milliseconds ago.
- dySE:一个 Java 搜索引擎的实现,第 3 部分 查询服务
- ExpandableTextView——一个可折叠的Textview
- 日期、字符串、时间戳之间的互相转换
- python for循环和range内置函数
- 我是如何入门、成长并进阶为数据分析师的?
- 操作系统(六)文件与文件系统
- hdoj1098 Ignatius's puzzle(数论)
- <转>javascript之Object.assign()痛点
- 第一次安装 iOS 应用获取网络权限
- 【raspberry】(一)认识树莓派
- 4. JavaScript 设计模式(适配器模式,外观模式)