Node.js examples for Date:Date Format
Pretty print date object
Date.prototype.pprint = function() { var Y = this.getUTCFullYear(); var M = this.getUTCMonth() + 1; var D = this.getUTCDate(); var h = this.getUTCHours(); var m = this.getUTCMinutes(); var s = this.getUTCSeconds(); return Y + "-" + M.pad() + "-" + D.pad() + " " + h.pad() + ":" + m.pad() + ":" + s.pad() + " UTC"; } Date.prototype.to_datetimepicker_format = function() { var Y = this.getUTCFullYear(); var M = this.getUTCMonth() + 1; var D = this.getUTCDate(); var h = this.getUTCHours(); var m = this.getUTCMinutes(); return Y + "-" + M.pad() + "-" + D.pad() + " " + h.pad() + ":" + m.pad(); } Number.prototype.pad = function() { var x = this.toString(); while(x.length < 2) { x = "0" + x; }/* www. ja va 2s .co m*/ return x; } Number.prototype.round = function(dp) { multiplier = Math.pow(10,dp); return Math.round(this*multiplier) / multiplier; }