// date
{{ post.published_at|date("m/d/Y") }}
// date time
{{ post.published_at|date('Y-m-d H:i:s') }}
{# 23:39 #}
{{ '2019-08-07 23:39:12'|format_datetime('none', 'short', locale='fr') }}
{# 07/08/2019 #}
{{ '2019-08-07 23:39:12'|format_datetime('short', 'none', locale='fr') }}
{# mercredi 7 août 2019 23:39:12 UTC #}
{{ '2019-08-07 23:39:12'|format_datetime('full', 'full', locale='fr') }}
{{ post.published_at|date("F jS a g:ia") }}
//
// Just create simple custom function to determine the class name
// and check is equal to DateTime
//
namespace AppBundleTwig;
use Twig_Extension;
use Twig_SimpleFunction;
class HelperExtension extends Twig_Extension
{
public function getFunctions()
{
return array(
new Twig_SimpleFunction('class', array($this, 'getClassName')),
);
}
public function getClassName($object)
{
if (!is_object($object)) {
return null;
}
return get_class($object);
}
}