I am using jenssegers/date and carbon
to display current date and time.
I can display full date in textual way by use of this code:
echo Date::now()->format('l j F Y H:i:s'); // example from jenssegers docs
Now, in a Codrops demo the date is presented as
<div class="slide__element slide__element--date">Saturday, 25<sup>th</sup> of October 2043</div>
How to build a helper to display the current date exactly in this fashion, including wrapping the th
(or nd
, st
) with the sup
element?
>>> \Carbon\Carbon::now()->format("l j <\s\up>S</\s\up> F Y H:i:s")
=> "Friday 4 <sup>th</sup> November 2016 22:11:16"
Note the s and u are escaped.
format()
takes a date formatting string, you can add whatever chars you want to that string, you just have to escape them if they match PHPs formatting string characters.