Home > php教程 > PHP源码 > body text

php 格式化输出日期函数

WBOY
Release: 2016-06-08 17:29:09
Original
1178 people have browsed it
<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;
 }

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template