如何将时区中的数据解析到这个php prettyprint库中,以便根据设置的时区打印出时间?
我目前正在使用打印我的时间。目前,它是吐出UTC时间,因为这是什么在MYSQL。我有一个如何将时区中的数据解析到这个php prettyprint库中,以便根据设置的时区打印出时间?,php,mysql,datetime,Php,Mysql,Datetime,我目前正在使用打印我的时间。目前,它是吐出UTC时间,因为这是什么在MYSQL。我有一个PrettyPrint.php组件: <?php namespace Component; use PrettyDateTime\PrettyDateTime, Phalcon\Mvc\User\Component, DateTime, Component\User; class PrettyPrint extends Component { public static
PrettyPrint.php
组件:
<?php
namespace Component;
use PrettyDateTime\PrettyDateTime,
Phalcon\Mvc\User\Component,
DateTime,
Component\User;
class PrettyPrint extends Component
{
public static function prettyPrint($dateTime, $refDateTime = 'now')
{
$user = new User();
date_default_timezone_set($user->getSessionUserTimeZone());
$getDateTimeObject = function($dateType) {
if (is_numeric($dateType)) { //Linux timestamp
$date = (new DateTime())->setTimestamp((int)$dateType);
} else if (is_string($dateType)) {
$date = new DateTime($dateType);
}
return $date;
};
$date = $getDateTimeObject($dateTime);
$refDate = $getDateTimeObject($refDateTime);
if (is_a($date, 'DateTime') && is_a($refDate, 'DateTime')) {
return PrettyDateTime::parse($date, $refDate);
}
}
public static function excerpt($string, $len = 10)
{
return substr($string, 0, $len);
}
}
将DateTime对象传递给此类,那么为什么不运行:
$date = new DateTime($inputDate, new DateTimeZone('UTC'));
$date->setTimezone(new DateTimeZone('New/Timezone'));
然后将$date传递给prettyprint类
然后,我在课堂上读了更多的书,并对此进行了思考。改变时区对这样的课程有什么影响吗?用户的时区是什么并不重要。59分钟前是59分钟前(无论如何在地球上)。哦,你说得对。我对课堂的了解不够深入,我在评论中看到了对时区的支持。非常感谢!
$date = new DateTime($inputDate, new DateTimeZone('UTC'));
$date->setTimezone(new DateTimeZone('New/Timezone'));