Skip to content

Instantly share code, notes, and snippets.

@benji07
Created March 18, 2010 21:12
Show Gist options
  • Save benji07/336897 to your computer and use it in GitHub Desktop.
Save benji07/336897 to your computer and use it in GitHub Desktop.
<?php
namespace Bundle\TestBundle\Helper;
use Symfony\Components\Templating\Helper\Helper;
use Symfony\Components\DependencyInjection\ContainerInterface;
use Symfony\Components\OutputEscaper\Escaper;
class DateHelper extends Helper
{
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function getName(){
return 'date';
}
public function format(\DateTime $date, $format = 'd', $culture = ''){
if($culture == ''){
$culture = $this->container->getUserService()->getCulture();
}
$d = $date->format('Y-m-d H:i:s');
$formater = new \IntlDateFormatter($culture,
\IntlDateFormatter::FULL,
\IntlDateFormatter::FULL,
date_default_timezone_get(),
\IntlDateFormatter::GREGORIAN ,
$format);
return $formater->format(strtotime($d));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment