所以,我试图显示时间戳,但我真的不知道该怎么做。 顺便说一下时间戳的介绍会很棒,我真的不知道它是什么,它做了什么。在初学者的水平上解释它。
时间戳应为秒。 第一条记录的时间戳始终为0,因为它表示饮酒会话的开始。
基本上,我想要的是会有一个按钮" +"这将自动显示时间戳......
用户添加摄入量的时间戳。时间戳是用户点击“+”按钮记录摄入量的时间。
注意:我希望它只能在php中完成..我不会要求代码只是指出我如何实现我想要的正确方向..谢谢!
答案 0 :(得分:1)
我还在学习自己,但这看起来像一个有趣的小项目,所以我想我会放弃它。您只需要两次更改路径。您可以使用css更改布局。
<?php
$timeNow = time();
//When a button is used, if action is set, than
if(isset($_GET['action'])){
//When reset button is used redirect to start page
if($_GET['action'] == 'Reset'){
header('Location: *path*'); //path to your file, e.g. file.php
}
//get all variables
$timeDiff = $_GET['timeDiff'];
$timeStart = $_GET['timeStart'];
$start = $_GET['start'];
//Make an array out of this string
$timeDiffArray = explode(',', $_GET['timeDiff']);
//iterate through the array
foreach($timeDiffArray AS $diff){
echo "Time: " . $diff . "<br>";
}
//First beer, do this
if($start == 'true'){
//change to false, not first loop anymore
$start = 'false';
//set time of Start
$timeStart = time();
//2 or more beer, do this
}else{
//Set difference between time first beer and start this beer
$diff = $timeNow - $timeStart;
// output last differense
echo "Time: " . $diff . "<br>";
//add difference to the timediff string
$timeDiff .= ',' . $diff;
}
//Start , if action is not set, than
}else{
$start = 'true'; //true because its going to be the first loop
$timeDiff = 0; //first always start with 0
$timeStart = null; //declaire $timeStart
echo 'No time set.';
}
//form
//path to your file, e.g. file.php
echo '<form action="*path*">
<input type="hidden" name="start" value="' . $start . '">
<input type="hidden" name="timeDiff" value="' . $timeDiff . '">
<input type="hidden" name="timeStart" value="' . $timeStart . '">
<input type="submit" name="action" value="Reset" />
<input type="submit" name="action" value="Submit">
</form>';
?>