分类
Magento PHP 后端

时间转化

$historyDate = '20022-06-27';
$date = new \DateTime($historyDate);
$date->setTimezone(new \DateTimeZone('Asia/Kolkata'));
echo $date->format('Y-m-d H:i:s');

private $timezone;

public function __construct(
    \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
)
{
    $this->timezone = $timezone;
}

public function execute()
{
    $this->timezone->date()->format('Y-m-d H:i:s');//获取时间格式 
    $this->timezone->date()->getTimestamp();//获取时间戳 
    $this->timezone->date()->getTimezone();  //时间区域
}