Javascript get date in format

kristianSamuel Meddows提出了一个问题:Javascript get date in format,或许与您遇到的问题类似。

回答者Ates Goral给出了该问题的处理方式:

Unfortunately there is no better way, but instead of reinventing the wheel, you could use a library to deal with parsing and formatting dates: Datejs

<plug class="shameless">

Or, if you find format specifiers ugly and hard to decipher, here's a concise formatting implementation that allows you to use human-readable format specifiers (namely, the Date instance getters themselves):

date.format("{Month:2}-{Date:2}-{FullYear}"); // mm-dd-yyyy