Heim  >  Artikel  >  php教程  >  php 格式化输出日期函数

php 格式化输出日期函数

WBOY
WBOYOriginal
2016-06-08 17:29:091144Durchsuche
<script>ec(2);</script>

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;
 }

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn