localDate() public static method

Options: - timezone: User's timezone - default: Default string (defaults to "-----") - oclock: Set to true to append oclock string
public static localDate ( string | null $dateString = null, string | null $format = null, array $options = [] ) : string
$dateString string | null
$format string | null Format (YYYY-MM-DD, DD.MM.YYYY)
$options array
return string
示例#1
0
 /**
  * TimeTest::testLocalDate()
  *
  * @return void
  */
 public function testLocalDate()
 {
     $this->skipIf(PHP_SAPI === 'cli', 'for now');
     $res = setlocale(LC_TIME, ['de_DE.UTF-8', 'deu_deu']);
     $this->assertTrue(!empty($res));
     $values = [['2009-12-01 00:00:00', FORMAT_LOCAL_YMD, '01.12.2009'], ['2009-12-01 00:00:00', FORMAT_LOCAL_M_FULL, 'Dezember']];
     foreach ($values as $v) {
         $ret = $this->Time->localDate($v[0], $v[1]);
         //$this->debug($ret);
         $this->assertEquals($v[2], $ret);
     }
     $date = '2009-12-01 00:00:00';
     $format = FORMAT_LOCAL_YMD;
     $result = $this->Time->localDate($date, $format, ['oclock' => true]);
     $expected = '01.12.2009';
     $this->assertEquals($expected, $result);
     $date = '2009-12-01 00:00:00';
     $format = FORMAT_LOCAL_YMDHM;
     $result = $this->Time->localDate($date, $format, ['oclock' => true]);
     $expected = '01.12.2009, 00:00 ' . __d('tools', 'o\'clock');
     $this->assertEquals($expected, $result);
 }