Check out moment.js ! This is a really powerful small date library in JavaScript.
Using the moment .js ...
var today = moment(new Date()); today.format("M/D/YYYY"); // "4/11/2012" today.format("MMMM D, YYYY h:m A"); // outputs "April 11, 2012 12:44 AM" // in one line... moment().format("M/D/YYY"); // "4/11/2012" moment().format("MMMM D, YYYY h:m A"); // outputs "April 11, 2012 12:49 AM"
Another example...
var a = moment([2012, 2, 12, 15, 25, 50, 125]); a.format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Monday, March 12th 2012, 3:25:50 pm" a.format("ddd, hA"); // "Mon, 3PM"
In addition, checkout date.js is worth noting. I think the two libraries complement each other.
source share