PHP Timestamp into DateTime

前端 未结 4 663
甜味超标
甜味超标 2021-01-31 01:04

Do you know how I can convert this to a strtotime, or a similar type of value to pass into the DateTime object?

The date I have:

Mon, 1         


        
4条回答
  •  暖寄归人
    2021-01-31 01:28

    it is my solution:

        function changeDateTimezone($date, $from='UTC', $to='Asia/Tehran', $targetFormat="Y-m-d H:i:s")
        {
            $date = new DateTime($date, new DateTimeZone($from));
            $date->setTimeZone(new DateTimeZone($to));
            return $date->format($targetFormat);
        }
    

提交回复
热议问题