[TYPO3-mvc] <f:format.date> shows "could not be parsed by DateTime constructor. " in the FE

Bastian Waidelich bastian at typo3.org
Mon Jul 12 13:28:57 CEST 2010


"Christian Müller (Kitsunet)" wrote:

Hi Steffen & Christian,

 >> <p class="date"><f:format.date>{items.datetime}</f:format.date></h2>
 >> In the FE I see the title ok, but where the date should go I see:
 >> "1278740610" could not be parsed by DateTime constructor.

> Did you specify your model property as DateTime object?

If you look inside the format.date ViewHelper class, you see that the 
parameter is passed directly to the DateTime constructor if it is not 
already a DateTime object:

if (!$date instanceof DateTime) {
	try {
		$date = new DateTime($date);
	} catch (Exception $exception) {
		throw new Tx_Fluid_Core_ViewHelper_Exception('"' . $date . '" could 
not be parsed by DateTime constructor.', 1241722579);
	}
}

The DateTime constructor accepts Unix timestamps too, but according to
According to http://www.php.net/manual/en/datetime.formats.php -> 
Compound Formats they have to be prefixed with @


 >> "1278740610" could not be parsed by DateTime constructor.

That's weird, I do not get an exception here, but "-99999.-99999.7406" ;)
If you prefix the value like
<f:format.date format="d.m.Y">@1278740610</f:format.date>
You should get the correct result (10.07.2010).

Best,
Bastian


More information about the TYPO3-project-typo3v4mvc mailing list