Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php的基本时间戳_Php - Fatal编程技术网

使用php的基本时间戳

使用php的基本时间戳,php,Php,所以,我试图显示时间戳,但我真的不知道怎么做。。 顺便说一句,时间戳的介绍将是伟大的,我真的不知道它是什么,它做什么。请解释它在初学者的水平 时间戳应为秒。 第一条记录始终具有0的时间戳,因为它表示饮酒会话的开始 基本上,我想要的是,将有一个按钮“+”将自动显示时间戳 用户添加摄入的时间戳。时间戳将是用户点击“+”按钮记录摄入量的时间 注意:我希望它只在php中完成。我不是在要求代码,只是告诉我如何实现我想要的。。谢谢 我仍在自学,但这看起来是一个有趣的小项目,所以我想我会放手去做。您只需更改路

所以,我试图显示时间戳,但我真的不知道怎么做。。 顺便说一句,时间戳的介绍将是伟大的,我真的不知道它是什么,它做什么。请解释它在初学者的水平

时间戳应为秒。 第一条记录始终具有0的时间戳,因为它表示饮酒会话的开始

基本上,我想要的是,将有一个按钮“+”将自动显示时间戳

用户添加摄入的时间戳。时间戳将是用户点击“+”按钮记录摄入量的时间


注意:我希望它只在php中完成。我不是在要求代码,只是告诉我如何实现我想要的。。谢谢

我仍在自学,但这看起来是一个有趣的小项目,所以我想我会放手去做。您只需更改路径两次。您可以使用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>';
?> 


听起来像一个计数器,而不是一个timesptamp。你可以使用time()来准确地给出一个时间戳,然后再做一次,从每一圈中减去秒数。顺便说一句,听起来是个有趣的应用程序。啤酒节应用程序?哈哈…实际上是血液酒精含量计算器…时间()…好的,我来看看。。。