Home  >  Article  >  php教程  >  php 格式化输出日期函数

php 格式化输出日期函数

WBOY
WBOYOriginal
2016-06-08 17:29:091087browse

php 格式化输出日期函数

public function format ($formatTo='standard',$timestamp = NULL) {
  if ($timestamp!==NULL) {
   $source = $timestamp;
   if (!$source) {
    return '';
   }
  } else {
   $source = $this->timestamp;
  }
  
  switch (strtolower($formatTo))
  {
   case 'chinese' : //中文格式串“YYYY年MM月DD日

HH:MM:SS”
    $result = date("Y年m月d日 H:i:s", $source);

break ;
   case 'cdate':
    $result = date("Y年m月d日", $source); break

;
   case 'date':
    $result = date("Y-m-d", $source); break ;
   case 'time':
    $result = date("H:i:s", $source); break ;
   case 'standard' : //标准格式串“YYYY-MM-DD HH:MM:SS


    $result = date("Y-m-d H:i:s", $source);

break;
   default :
    $result = date($formatTo, $source);
  }
  return $result;
 }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn