time.js 686 B

123456789101112131415161718192021222324
  1. Date.prototype.Format = function(fmt) {
  2. var o = {
  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+)/.test(fmt))
  12. fmt = fmt.replace(
  13. RegExp.$1,
  14. (this.getFullYear() + "").substr(4 - RegExp.$1.length)
  15. );
  16. for (var k in o)
  17. if (new RegExp("(" + k + ")").test(fmt))
  18. fmt = fmt.replace(
  19. RegExp.$1,
  20. RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
  21. );
  22. return fmt;
  23. };