How can I easily convert dates from UTC via PHP?

前端 未结 8 2359
梦谈多话
梦谈多话 2020-12-01 17:07

I am storing dates in a MySQL database in datetime fields in UTC. I\'m using PHP, and I\'ve called date_timezone_set(\'UTC\') so that all calls to date() (without timestamp)

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 17:43

    setTimezone(new DateTimeZone(trim($to_dtz)));
                $time_now_object->setTimezone(new DateTimeZone(trim($to_dtz)));
                // Is day = day in $time_now_object, $time_object..?
                if ($time_now_object->format('d') == $time_object->format('d')) {
                    return $time_object->format('H:i:s');
                } else {
                    return $time_object->format('Y-m-d H:i:s');
                }
            } else {
                return '';
            }
        }
    ?>
    

    Use sample:

    
    

提交回复
热议问题