To answer that question on Stackoverflow, the easiest (and laziest?) answer would have been to recommend using moment.js (which is really my preferred non-wheel-inventing way).

Six years after the question was asked, a user came up with an epic answer that became a library by itself.