PHP date()-style formatting for JavaScript
If you’ve ever had to work with the JavaScript Date
object, you might have come accross the same problem that I had recently: formatting dates and times in a nice way is difficult to do. The options you get for producing date and time strings are limited, at best: aside from a few predefined, not very pretty formats, no functions are provided at all for this type of thing.
At the other end of the spectrum, PHP provides a function called date()
, which takes a format string somewhat reminiscent of printf
-type functions, along with a Unix timestamp, and provides a wide variety of options for formatting dates and times to your heart’s content. So I figured, why not take that concept to JavaScript?