Formatting date is a common task, like converting timestamp to "yyyy-MM-dd hh:mm:ss" format (e.g. 2013-03-03 12:00:00)
Date.format function can do this job
1 2 3 |
var d = new Date(); console.log(d.format('yyyy-MM-dd hh:mm:ss')); |
But it only works in Chrome, but not work in IE and Firefox.
Here we can use Moment.js library to format the date (Moment.js is a cross-browser date library)
1 |
console.log(moment().format('YYYY-MM-DD HH:mm:ss')) |