Custom Function Sharing of Converting US Time to Beijing Time in php

  • 2021-07-10 19:02:22
  • OfStack

Due to the time conversion used in the email system recently, it is necessary to convert the email time downloaded from Google gmail into Beijing time, so I wrote a time conversion function, hoping to enlighten all the friends in need. We all know that the time difference between China and the United States is 13 hours. The following code is directly provided:


function datezhuanhuan($dateparams)
{
$ccc=strtotime($dateparams);
$date=date( ' Y-m-d');
$bjtime=date( ' Y-m-d',$ccc);
if($date==$bjtime)
{
$sbjtime=date( ' Y-m-d H:i:s',$ccc);
echo substr($sbjtime,11,5);
}
else
{
$sbjtime=date( ' Y-m-d H:i:s',$ccc);
return substr($sbjtime,5,5);
}
}

Another +8-hour algorithm:


$bj_time = date ("Y-m-d H:i:s" , mktime(gmdate('H')+8,gmdate('i'),gmdate('s'),gmdate('m'),gmdate('d'),gmdate('Y')));

Related articles: