xxxxxxxxxx
{# 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') }}
xxxxxxxxxx
// date
{{ post.published_at|date("m/d/Y") }}
// date time
{{ post.published_at|date('Y-m-d H:i:s') }}
xxxxxxxxxx
{{ now | date('d.m.Y') }} // Output: 25.04.2023
//These are all the letters you can use to format the time to your liking:
{{ now | date('d') }} //(e.g. "09") day of the month with leading zeros
{{ now | date('D') }} //(e.g. "Tue") abbreviation of day of the week
{{ now | date('j') }} //(e.g. "9") day of the month without leading zeros
{{ now | date('l') }} //(e.g. "Tuesday") full name of the day of the week
{{ now | date('F') }} //(e.g. "January") full name of the month
{{ now | date('m') }} //(e.g. "01") month with leading zeros
{{ now | date('M') }} //(e.g. "Jan") abbreviation of the month
{{ now | date('n') }} //(e.g. "1") month without leading zeros
{{ now | date('Y') }} //(e.g. "2023") year
{{ now | date('y') }} //(e.g. "23") two-digit year
{{ now | date('g') }} //(e.g. "9") hour in 12-hour format without leading zeros
{{ now | date('G') }} //(e.g. "9") hour in 24-hour format without leading zeros
{{ now | date('h') }} //(e.g. "09") hour in 12-hour format with leading zeros
{{ now | date('H') }} //(e.g. "09") hour in 24-hour format with leading zeros
{{ now | date('i') }} //(e.g. "03") minutes with leading zeros
{{ now | date('s') }} //(e.g. "09") seconds with leading zeros
{{ now | date('a') }} // lowercase "am" or "pm"
{{ now | date('A') }} // uppercase "AM" or "PM"
{{ now | date('T') }} //(e.g. "EST") timezone abbreviation
{{ now | date('O') }} //(e.g. "+0200") difference to Greenwich time (GMT) in hours
{{ now | date('P') }} //(e.g. "+02:00") difference to Greenwich time (GMT) with colon
xxxxxxxxxx
//
// Just create simple custom function to determine the class name
// and check is equal to \DateTime
//
namespace AppBundle\Twig;
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);
}
}