如何创建日期格式UTC php



我有这个DateTime格式:

2020-08-27 19:00:00

并且我想转换为以下格式:
Thu Aug 27 2020 19:00:00 GMT-0500 (hora estándar de Colombia)

我的php版本是5我能怎么做吗感谢

我要把骨头扔给你,因为约会很难。您可以使用基本的date函数和strtotime来完成所需的一切,诀窍是找出要使用的格式化标志。你会在时区度过一段糟糕的时光,所以要做好为此付出代价的准备。您的日期输入没有任何时区信息,所以您的输出将使用PHP实例中设置的任何内容。

祝你好运。

<?php
$dateInput = '2020-08-27 19:00:00';
$time = strtotime($dateInput);
/*
Thu Aug 27, 2020 19:00 EDT-0400 (America/New_York)
The timezone will depend on what's set in your PHP instance. Look at date_default_timezone_set
*/
$output = date('D M j, Y H:i TO (e)', $time);
echo $output.PHP_EOL;
/*
Thu Aug 27, 2020 19:00 EDT-0400 (hora estándar de Colombia)
"hora estándar de Colombia" isn't a thing that php dates can do, so you have to hard code it.
Escape all non-format characters. Some are safe, but let's just nuke it from orbit. If this is more than
a one-off, write a function to escape the fancy timezone string.
*/
$output = date('D M j, Y H:i TO (hora estándar de Colombia)', $time);
echo $output.PHP_EOL;

最新更新