Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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_Mysql_Timestamp - Fatal编程技术网

Php 将时间戳转换为秒时出现问题

Php 将时间戳转换为秒时出现问题,php,mysql,timestamp,Php,Mysql,Timestamp,基本上,我要做的是将mysql时间戳转换为“xx秒前”格式。我使用这个函数-$age=time()-strottime($eventTime)。我得到结果,但它以秒为单位显示时间1一小时后(-3600秒)。例如,如果我现在发布,就会显示(-3600年代前)。这可能是什么问题?假设您的MySQL会话和PHP设置都共享同一时区,您可以使用类似的方法来获取合适的英语时间段: function toFriendlyTime($seconds) { // Used in the item view

基本上,我要做的是将mysql时间戳转换为“xx秒前”格式。我使用这个函数-$age=time()-strottime($eventTime)。我得到结果,但它以秒为单位显示时间1一小时后(-3600秒)。例如,如果我现在发布,就会显示(-3600年代前)。这可能是什么问题?

假设您的MySQL会话和PHP设置都共享同一时区,您可以使用类似的方法来获取合适的英语时间段:

function toFriendlyTime($seconds) {
    // Used in the item view, this function returns a 'friendly', rough-idea type time, like "3 hours" or "4 months"
    $measures = array(
        'month'=>30*24*60*60,
        'week'=>7*24*60*60,
        'day'=>24*60*60,
        'hour'=>60*60,
        'minute'=>60,
        'second'=>1,
    );
    foreach ($measures as $label=>$amount) {
        if ($seconds >= $amount) {
            $howMany = floor($seconds / $amount);
            return $howMany." ".$label.($howMany > 1 ? "s" : "");
        }
    }
    return "1 second";
}

如果不查看您的数据,就不能说太多,这可能是因为您生成的$eventTime与您检查的服务器之间有1小时的间隔
time()
嗯,我使用的是本地托管。我想知道时区设置或smth在哪里?你如何为
$eventTime
时区创建值不重要,因为这两个函数都应该以UTC/GMT为单位给出秒数。那么你是说无论
$age
的值大于3600吗?$eventTime=$row['time']“time”是创建表记录时的timestap。