将 3 小时添加到 new Cassandra\Timestamp() 在 php 中生成的时间戳

我在 php 中使用生成了时间戳new Cassandra\Timestamp()。现在我想使用 php 将 2 小时添加到这个生成的时间,然后将其存储在数据库 (Cassandra) 中。


本质上我想做这样的事情:


$dt= new Cassandra\Timestamp();

$new_dt= $dt+3*3600; //here 3 is in hours


$query=$session->prepare('INSERT INTO tracker_table(id,deadline)VALUES(?,?)');

       $session->execute($query,array('arguments'=>array(new \Cassandra\Uuid(),$new_dt)));

**HERE deadline 列的数据类型设置为时间戳。


我在这里面临的问题是 $dt 返回一个对象数据类型,所以我不能直接向它添加 3 小时。即使我能够以某种方式增加 3 小时,cassandra 也不会接受它作为可行的输入。


那么,是否可以通过这种方式直接将 3 小时添加到 cassandra 时间戳,或者我应该处理在 DB 中存储为字符串的时间。


我的结局是存储截止日期,然后将当前时间与存储的截止日期进行比较,如果当前时间大于则执行一些代码。是这样的:


 $current_time=time();

 if ($current_time>$deadline){echo "hello"; }


拉风的咖菲猫
浏览 102回答 1
1回答

人到中年有点甜

这应该可以完成工作;$now = time(); // get current timestamp$new_dt = new Cassandra\Timestamp($now + (3 * 3600));
打开App,查看更多内容
随时随地看视频慕课网APP