mysql>select current_timestamp, current_timestamp()
+---------------------+---------------------+
| current_timestamp | current_timestamp() |
+---------------------+---------------------+
| 2008-08-09 23:22:24 | 2008-08-09 23:22:24 |
+---------------------+---------------------+
2. MySQL (Unix 时间戳、日期)转换函数:
unix_timestamp(),
unix_timestamp(date),
from_unixtime(unix_timestamp),
from_unixtime(unix_timestamp,format)
下面是示例:
select unix_timestamp()-- 1218290027
select unix_timestamp('2008-08-08')-- 1218124800
select unix_timestamp('2008-08-08 12:30:00')-- 1218169800
select from_unixtime(1218290027)-- '2008-08-09 21:53:47'
select from_unixtime(1218124800)-- '2008-08-08 00:00:00'
select from_unixtime(1218169800)-- '2008-08-08 12:30:00'
select from_unixtime(1218169800, '%Y %D %M %h:%i:%s %x')-- '2008 8th August 12:30:00 2008'
3. MySQL 时间戳(timestamp)转换、增、减函数:
timestamp(date) -- date to timestamp
timestamp(dt,time) -- dt + time
timestampadd(unit,interval,datetime_expr) --
timestampdiff(unit,datetime_expr1,datetime_expr2) --
请看示例部分:
select timestamp('2008-08-08')-- 2008-08-08 00:00:00
select timestamp('2008-08-08 08:00:00', '01:01:01')-- 2008-08-08 09:01:01
select timestamp('2008-08-08 08:00:00', '10 01:01:01')-- 2008-08-18 09:01:01
select timestampadd(day, 1, '2008-08-08 08:00:00')-- 2008-08-09 08:00:00
select date_add('2008-08-08 08:00:00', interval 1 day)-- 2008-08-09 08:00:00
MySQL timestampadd() 函数类似于 date_add()。
select timestampdiff(year,'2002-05-01','2001-01-01')-- -1
select timestampdiff(day ,'2002-05-01','2001-01-01')-- -485
select timestampdiff(hour,'2008-08-08 12:00:00','2008-08-08 00:00:00')-- -12
select datediff('2008-08-08 12:00:00', '2008-08-01 00:00:00')-- 7
MySQL timestampdiff() 函数就比 datediff() 功能强多了,datediff() 只能计算两个日期(date)之间相差的天数。
直接使用的 int 好,毕竟时间戳可以用FROM_UNIXTIME等时间函数转换成时间格式, int 比datetime计算和比较简单一点,还有是就是感觉数据量大度的话int应该比datetime更快一点。
公司数据库大牛知,建的道所有的数据表关于时间的都是intint比datetime计算简单,数据量大的话int比datetime储存速度更快一点。
时间戳,一个完整的、可验证的数据块,它表示在特定时间之前存在的一段数据,通常是一个字符序列,标识某个时刻的时间。
利用数字签名技术生成下一代数据,签名对象包括原始文件信息、签名参数、签名时间等信息。广泛应用于,知识产权保护、合同签订、财务核算、电子报价投标、股票交易等领域。
扩展资料:
有两种类型的时间戳:
1.自建时间戳:这种时间戳是获取时间接收设备到时间戳服务器的时间戳,并通过时间戳服务器发出时间戳证书。该时间戳可用于企业内部责任的确定,经法院证明不具有法律效力。它不能作为一个法律基础,因为它很可能被篡改时,接收设备收到的时间。
2.具有法律效力的时间戳:是由中国科学院国家时间中心和北京联合信托技术服务有限公司共同打造的中国第三方可信时间戳认证服务。国家计时中心负责计时和准时监控。
mysql 时间戳最大值只能到 2038-01-19 03:14:07
参考地址
https://dev.mysql.com/doc/refman/8.0/en/datetime.html
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)