Check out moment.js ! This is a "small javascript date library for parsing, managing and formatting dates." This is a really powerful library.
Here is an example ...
var today = moment(new Date()); today.format("MMMM D, YYYY h:m A"); // outputs "April 11, 2012 2:32 PM" // in one line... moment().format("MMMM D, YYYY h:m A"); // outputs "April 11, 2012 2:32 PM"
Here is 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" a.format("D/M/YYYY"); // "12/3/2012"
In addition, checkout date.js is worth noting. I think the two libraries complement each other.
source share