我在Java应用程序中使用MySQL,
目的是通过从客户端向我的服务器发送一些信息来在线激活我的应用程序。
在我的服务器上,我使用时间戳记来获取客户端时间,然后我想给客户端30小时的试用期,然后该应用可以检查它是否仍在试用中或试用期已结束。
对不起,这些话,
但我需要的是获取时间戳,然后在时间戳结束后30小时计算,以将值实际分配给另一个字段0,1。
有什么建议么 ??谢谢。所有
最佳答案
您将需要以下内容:
$start = date("Y-m-d H:i:s"); //eg: 2018-12-16 00:00:00
$expire = date("Y-m-d H:i:s", strtotime("+30 hours")); //eg: 2018-12-17 04:00:00
那么您必须像对当前时间一样进行检查。您可以通过多种方式进行操作。
a)从数据库中选择:
$starttime = date("Y-m-d H:i:s", strtotime("-30 hours")); //gives now - 30hours
$query = $mysqli->query("SELECT * FROM Auth WHERE starttime >='".$starttime."';");
while ($row = $query->fetch_assoc()) {
// do something....
}
b)比较当前时间与用户的过期时间:
$starttime = date("Y-m-d H:i:s", strtotime("-30 hours")); //gives now - 30hours
$query = $mysqli->query("SELECT * FROM Auth WHERE SerialNumber='1234';");
$row = $query->fetch_assoc();
if ($row['starttime']) >= $starttime){
// do something....
}
关于java - MySQL时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53843409/