Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. //Author: meizz
  2. "use strict";
  3.  
  4. Date.prototype.format = function (format)
  5. {
  6. var obj = {
  7. "M+": this.getMonth() + 1, //month
  8. "d+": this.getDate(), //day
  9. "h+": this.getHours(), //hour
  10. "m+": this.getMinutes(), //minute
  11. "s+": this.getSeconds(), //second
  12. "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
  13. "S": this.getMilliseconds() //millisecond
  14. };
  15.  
  16. if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
  17. (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  18. for (var k in obj)
  19. if (new RegExp("(" + k + ")").test(format))
  20. format = format.replace(RegExp.$1,
  21. RegExp.$1.length == 1 ? obj[k] :
  22. ("00" + obj[k]).substr(("" + obj[k]).length));
  23. return format;
  24. };
  25.  
  26. alert(new Date().format("yyyy-MM-dd"));
  27. alert(new Date("january 12 2008 11:12:30").format("yyyy-MM-dd hh:mm:ss"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement