Join the DZone community and get the full member experience.Join For Free
It's structured much like the Perl-only solution, with a default
"/" route and a
<head> on line 38 that would receive a date and a formatting style, outputting the resulting formatted date.
Worth noting is the double equals sign (
<%== %>) when embedding a Perl expression. This prevents Mojolicious from XML-escaping special characters, e.g., replacing
toLocaleString() method for my formatting on line 12. There are other ways to do this:
- Date objects also have a
toLocaleDateStringmethod. However, Mozilla has a performance note that states it's better to use the
Intl.DateTimeFormat's browser support stands at about 70%, leaving out Safari (that's Mac, iPhone, and iPad) and Internet Explorer users.
Date constructor using the ,
_0, and methods of our Perl object;
month_0 because the
Dates can be constructed in many ways; this seemed the simplest without having to explain things like epochs and inconsistent parsing.
Why are we using Perl
Published at DZone with permission of Mark Gardner, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.