dongnuo6310 2019-05-16 19:17
浏览 95

获取当前时间,将其设置为不更新的变量[重复]

i want to get the current time and set it to a variable . after that i want to get the current time and subtract the variable from it . this way i can get the elapsed time. can anyone help ? Edit: wihtout the use of a database.. is this possible?

$firsttime = time();  #ofcourse this is going to update to current time 
#which is my problem

$diff = time() - $firsttime;
echo "<br>";
echo "<br>";
echo "You visited this page ",$diff," seconds ago";
</div>
  • 写回答

1条回答 默认 最新

  • dousi6303 2019-05-16 19:21
    关注

    It appears you are running two time() functions one right after the other, therefore the difference is in milliseconds. I believe what you want to do is store a cookie on the browser or store the time in a session (firsttime) and compare that value on the subsequent request.

    You may then wish to update that cookie/session to the new time so you can see the time differences between page visits.

    On the final line, shouldn't those commas be periods?

    评论

报告相同问题?

悬赏问题

  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器