2016-11-25 53 views
0

我有数据库。我在1480079589时间保存我的价值。 我想测量当前时间和我保存的数据库时间之间的时间。php当前时间和数据库时间的时差

我没有任何想法,因为我不懂时间逻辑。 1480079589是什么时间?

回答

1

为了计算时间差

SELECT timestamp AS 'thisisit' 
    FROM table 
WHERE TIMESTAMPDIFF(MINUTE, timestamp, NOW()) <= 15; 

这是一个timestamp

使用PHP的date()函数。

实施例:

echo date('m/d/Y', 1480079589); 

简单地说,Unix时间戳是跟踪时间作为行驶 总的秒的方式。这个计数开始于1月1日的Unix Epoch,在UTC为1970年的 。因此,Unix时间戳只是特定日期和Unix Epoch之间的秒数 。也应该指出,这个时间点在技术上不会改变没有 事情你在地球上的位置。这对于 计算机系统非常有用,用于在动态 和在线和客户端的分布式应用程序中跟踪和分类日期信息。原因 为什么Unix时间戳被许多网站管理员使用是因为他们可以一次代表所有时区的 。

请参阅此信息的详细信息: http://php.net/manual/en/datetime.settimestamp.php

参照这个问题太: What is a Unix timestamp and why use it?

0

1480079589是时间戳,就是1970-01-从时间划时代的秒数( 01 00:00:00)。这意味着距离地标仅有1480079589秒。

date('Y-m-d H:i:s',1480079589);

将以友好的方式打印日期,供您查看

0

这就是UNIX时间。

The unix time stamp is a way to track time as a running total of seconds. 
This count starts at the Unix Epoch on January 1st, 1970 at UTC. 
Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch. 
It should also be pointed out (thanks to the comments from visitors to this site) that this point in time technically does not change no matter where you are located on the globe. This is very useful to computer systems for tracking and sorting dated information in dynamic and distributed applications both online and client side. 

要获得时差试试这个:

<?php 
$databaseTime = 1480079589; // Time from DataBase 
print(time() - $databaseTime); // How much second 
+0

我想检查这个时间差是不是15分钟?我如何在UNIX时间写入15? – catcher

0

时间格式为秒,因为午夜1/1/1970。也称为Unix时间或时间戳。 你得到这是php与time()函数。为了衡量时间流逝,你可以比较两个时间戳并获得中间的秒数。 您使用

gmdate("M d Y H:i:s", $unixTimestamp); 
date("M d Y H:i:s", $unixTimestamp); 
0

我在SQL查询中使用

DATE_SUB(NOW(),INTERVAL 5 MINUTE) 

时间戳转换为人类可读的格式。我的问题解决了。

相关问题