date-ext.js 614 B

123456789101112131415161718192021
  1. Date.prototype.format = function(format) {
  2. var date = {
  3. "M+": this.getMonth() + 1,
  4. "d+": this.getDate(),
  5. "h+": this.getHours(),
  6. "m+": this.getMinutes(),
  7. "s+": this.getSeconds(),
  8. "q+": Math.floor((this.getMonth() + 3) / 3),
  9. "S+": this.getMilliseconds()
  10. };
  11. if(/(y+)/i.test(format)) {
  12. format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  13. }
  14. for(var k in date) {
  15. if(new RegExp("(" + k + ")").test(format)) {
  16. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
  17. date[k] : ("00" + date[k]).substr(("" + date[k]).length));
  18. }
  19. }
  20. return format;
  21. }