Tools\Utility\Time::niceTime PHP Method

niceTime() public static method

Takes time as hh:mm:ss or YYYY-MM-DD hh:mm:ss
public static niceTime ( string $time ) : string
$time string
return string Time in format hh:mm
    public static function niceTime($time)
    {
        if (($pos = strpos($time, ' ')) !== false) {
            $time = substr($time, $pos + 1);
        }
        return substr($time, 0, 5);
    }

Usage Example

コード例 #1
0
ファイル: TimeTest.php プロジェクト: alescx/cakephp-tools
 /**
  * TimeTest::testNiceTime()
  *
  * @return void
  */
 public function testNiceTime()
 {
     $result = $this->Time->niceTime('22:11:18');
     $expected = '22:11';
     $this->assertEquals($expected, $result);
     $result = $this->Time->niceTime('2014-11-12 22:11:18');
     $this->assertEquals($expected, $result);
 }