public function testConstructor2() { $dt = new DateTimeObject('14.02.2013'); $dt->setFormat('d.m.Y'); $this->assertSame('14.02.2013', $dt->val()); }
/** * Create a DateTimeObject from the given $time and $format. * * @param string|int $time Timestamp. * @param null|string $format Format in which the current timestamp is defined. * * @return DateTimeObject * @throws DateTimeObjectException */ public static function createFromFormat($time, $format = null) { if (self::isNull($format)) { $format = self::$defaultFormat; } try { $date = \DateTime::createFromFormat($format, $time); if (!$date) { throw new DateTimeObjectException(DateTimeObjectException::MSG_UNABLE_TO_CREATE_FROM_FORMAT); } } catch (\Exception $e) { throw new DateTimeObjectException(DateTimeObjectException::MSG_UNABLE_TO_CREATE_FROM_FORMAT); } try { $dt = new DateTimeObject(); $dt->setTimestamp($date->getTimestamp()); $dt->setFormat($format); } catch (\Exception $e) { throw new DateTimeObjectException(DateTimeObjectException::MSG_UNABLE_TO_CREATE_FROM_FORMAT); } return $dt; }