tools.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Created by vian on 2017/3/30.
  3. */
  4. //time tools
  5. Date.prototype.format = function(fmt)
  6. {
  7. var o = {
  8. "M+" : this.getMonth()+1, //月份
  9. "d+" : this.getDate(), //日
  10. "h+" : this.getHours(), //小时
  11. "m+" : this.getMinutes(), //分
  12. "s+" : this.getSeconds(), //秒
  13. "q+" : Math.floor((this.getMonth()+3)/3), //季度
  14. "S" : this.getMilliseconds() //毫秒
  15. };
  16. if(/(y+)/.test(fmt))
  17. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  18. for(var k in o)
  19. if(new RegExp("("+ k +")").test(fmt))
  20. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  21. return fmt;
  22. }
  23. //
  24. function getQueryString(name)
  25. {
  26. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  27. var r = window.location.search.substr(1).match(reg);
  28. if(r!=null)return unescape(r[2]); return null;
  29. }