format() public method

Format a date according to the pattern.
public format ( $time, $pattern = 'F', $charset = 'UTF-8' ) : string
return string formatted date time.
Ejemplo n.º 1
0
 public function testCustomPatterns()
 {
     $dateFormatter = new DateFormat();
     $time = @mktime(9, 9, 9, 9, 1, 2004);
     $pattern = "'Hello' EEEE, 'it should be' MMM yyyy HH:mm:ss!!!";
     $wants = 'Hello Wednesday, it should be Sep 2004 09:09:09!!!';
     $this->assertEquals($wants, $dateFormatter->format($time, $pattern));
 }
Ejemplo n.º 2
0
 /**
  * Renders the localized version of the date-time value.
  * If the culture is not specified, the default application
  * culture will be used.
  * This method overrides parent's implementation.
  */
 protected function getFormattedDate()
 {
     $value = $this->getValue();
     $defaultText = $this->getDefaultText();
     if (empty($value) && !empty($defaultText)) {
         return $this->getDefaultText();
     }
     $app = $this->getApplication()->getGlobalization();
     //initialized the default class wide formatter
     if (self::$formatter === null) {
         self::$formatter = new DateFormat($app->getCulture());
     }
     $culture = $this->getCulture();
     //return the specific cultural formatted date time
     if (strlen($culture) && $app->getCulture() !== $culture) {
         $formatter = new DateFormat($culture);
         return $formatter->format($value, $this->getPattern(), $this->getCharset());
     }
     //return the application wide culture formatted date time.
     $result = self::$formatter->format($value, $this->getPattern(), $this->getCharset());
     return $result;
 }