[TYPO3-mvc] f:format.date timezone "problem"?

Christian Zenker christian.zenker at 599media.de
Thu Jul 29 10:59:40 CEST 2010


> I added a new getter "getLocalDate()" which does this:
>
> public function getLocalDate() {
> 	$now = new DateTime();
> 	$offset = $now->getOffset();
>
> 	return new DateTime('@' . ($this->date + $offset));
> }

I do NOT recommend doing it this way!
Set the timezone of the DateTime-object correctly and you are fine. If  
you'd render your DateTime with the timezone displayed (like "Y-m-d  
H:i:sT") still UTC would be displayed. So you should do something like  
that:

$dateTime = new DateTime('@'.$this->date);
$dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
return $dateTime;

Or you could try my proposed DateTimeViewHelper where you can use an  
integer timestamp. This should not have the above mentioned problems. It  
uses strftime-syntax though:
http://forge.typo3.org/projects/package-viewhelperincubator/repository/show/DateTimeViewHelper/_Extension/trunk

Christian.


More information about the TYPO3-project-typo3v4mvc mailing list