Javascript Date toCustomFormat()
var prependZero = function(num) { return (num < 10)? ("0" + num) : num; } Date.prototype.toCustomFormat = function() { var h = this.getHours(), h_12hr = (h % 12),/* www. j a v a 2 s.c o m*/ hh = prependZero((h_12hr == 0)? 12 : h_12hr), mm = prependZero(this.getMinutes()), ss = prependZero(this.getSeconds()), a = (h >= 12)? "pm" : "am"; return (this.toString("MMM dd, yyyy") + " " + hh + ":" + mm + ":" + ss + " " + a); }