tools.js 867 B

123456789101112131415161718192021222324252627282930313233
  1. function sleep(delay) {
  2. var start = new Date().getTime();
  3. while (new Date().getTime() - start < delay) {
  4. continue;
  5. }
  6. }
  7. Date.prototype.Format = function (fmt) {
  8. //author: meizz
  9. var o = {
  10. "M+": this.getMonth() + 1, //月份
  11. "d+": this.getDate(), //日
  12. "h+": this.getHours(), //小时
  13. "m+": this.getMinutes(), //分
  14. "s+": this.getSeconds(), //秒
  15. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  16. S: this.getMilliseconds(), //毫秒
  17. };
  18. if (/(y+)/.test(fmt))
  19. fmt = fmt.replace(
  20. RegExp.$1,
  21. (this.getFullYear() + "").substr(4 - RegExp.$1.length)
  22. );
  23. for (var k in o)
  24. if (new RegExp("(" + k + ")").test(fmt))
  25. fmt = fmt.replace(
  26. RegExp.$1,
  27. RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
  28. );
  29. return fmt;
  30. };