Exemple #1
0
 /**
  * Format a date by the given strftime()-like format string.
  *
  * These format tokens are not supported intentionally:
  * %a, %A, %b, %B, %c, %h, %p, %U, %x, %X
  *
  * @see     php://strftime
  * @param   string format
  * @param   util.TimeZone outtz default NULL
  * @return  string
  * @throws  lang.IllegalArgumentException if unsupported token has been given
  */
 public function format($format, TimeZone $outtz = null)
 {
     return preg_replace_callback('#%([a-zA-Z%])#', [$outtz === null ? $this : $outtz->translate($this), 'formatCallback'], $format);
 }
Exemple #2
0
 /**
  * Format a date by the given strftime()-like format string.
  *
  * These format tokens are not supported intentionally:
  * %a, %A, %b, %B, %c, %h, %p, %U, %x, %X
  *
  * @see    php://strftime
  * @param  string $format
  * @param  util.TimeZone $outtz default NULL
  * @return string
  * @throws lang.IllegalArgumentException if unsupported token has been given
  */
 public function format(string $format, TimeZone $outtz = null) : string
 {
     static $replace = ['%d' => 'd', '%m' => 'm', '%Y' => 'Y', '%H' => 'H', '%S' => 's', '%w' => 'w', '%G' => 'o', '%D' => 'm/d/Y', '%T' => 'H:i:s', '%z' => 'O', '%Z' => 'e', '%G' => 'o', '%V' => 'W', '%C' => 'y', '%e' => 'j', '%G' => 'o', '%H' => 'H', '%I' => 'h', '%j' => 'z', '%M' => 'i', '%r' => 'h:i:sa', '%R' => 'H:i:s', '%u' => 'N', '%V' => 'W', '%W' => 'W', '%w' => 'w', '%y' => 'y', '%Z' => 'O', '%t' => "\t", '%n' => "\n", '%%' => '%'];
     return date_format(($outtz === null ? $this : $outtz->translate($this))->handle, strtr($format, $replace));
 }