Custom function sharing between Pacific time and Beijing time realized by php

  • 2021-07-13 04:31:09
  • OfStack

There is nothing to say, just go to the code:


/**

 *  Pacific Time to Beijing Time 

 */

public function pacificToPRC($time=''){

 date_default_timezone_set('Pacific/Apia');

 if(empty($time)){

 $time = time();

 }

 date_default_timezone_set('Asia/Shanghai');

 $date = date('Y-m-d H:i:s',$time);

 $time = strtotime($date);

 return $time;

}
/**

 *  Beijing time to Pacific time 

 * @param unknown_type $time

 */

public function PRCToPacific($time=''){

 if(empty($time)){

 date_default_timezone_set('Asia/Shanghai');

 $time = time();

 }

 date_default_timezone_set('Pacific/Apia');

 $date = date('Y-m-d H:i:s',$time);

 $time = strtotime($date);

 return $time;

}

Related articles: