Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to set a variable $time to the current time and then date following this format: HH:mm:ss On day/month/year.
Could anyone help me to do that in symfony?
Have you tried with the built-in date function?
date
$time = date('H:i:s \O\n d/m/Y');
This should work until 2038 :) Both O and n need to be escaped, as they have a special meaning within the format string.
O
n
Add a comment
As you are using Symfony2 and you are looking for a way to display a date, you can do this directly in your twig template with:
{{ "now"|date("H:i:s \O\n d/m/Y") }}
http://twig.sensiolabs.org/doc/filters/date.html
This is the same as in any other PHP application:
$time = new \DateTime(); echo $time->format('H:i:s \O\n Y-m-d');
The \ before O and n are necessary to prevent DateTime::format from interpreting the characters as date codes and output them literally.
\
DateTime::format
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.