Where can I find documentation on formatting a date in JavaScript?
I love 10 ways to format time and date using JavaScript and Working with Dates.
Basically, you have three methods and you have to combine the strings for yourself:
getDate() // Returns the date
getMonth() // Returns the month
getFullYear() // Returns the year
Example:
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();
console.log(curr_date + "-" + curr_month + "-" + curr_year);
Moment.js
It is a (lightweight)* JavaScript date library for parsing, manipulating, and formatting dates.
var a = moment([2010, 1, 14, 15, 25, 50, 125]);
a.format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Sunday, February 14th 2010, 3:25:50 pm"
a.format("ddd, hA"); // "Sun, 3PM"
(*) lightweight meaning 9.3KB minified + gzipped in the smallest possible setup (feb 2014)