我试图在Wordpress中将Unix时间戳转换为EST时间。谁能告诉我该怎么做? 谢谢。
这里是将ISO时间戳转换为EST时间的代码。我想将Unix转换为EST。
function ptr_filter( $rdamtmp )
{
if( preg_match_all( "/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:\d{2}/", $rdamtmp, $matches) )
{
foreach( $matches[0] as $m )
{
$time = strtotime( $m );
$timezone = -4; //(GMT -4:00) EST (U.S. & Canada)
$text = gmdate( "l g:i a", $time + 3600 * ( $timezone + date("I") ) );
$rdamtmp = str_replace( $m, $text, $rdamtmp );
}
}
return $rdamtmp;
}
答案 0 :(得分:0)
$datetime = new \DateTime();
$datetime->setTimestamp($unixtimestamp);
$datetime->setTimezone(new \DateTimeZone('America/New_York'));
echo $datetime->format('m/d/Y H:i:s T');