常用JS代碼收集

// JavaScript Document
Utility = {
	getReqId: function(url){
		var str = "req_id=";
		var idx = url.indexOf(str);
		var reqid = url.slice(idx + str.length);
		var re = /[a-zA-Z0-9]+/;
		return reqid.match(re);
	},
	toDateString: function(C) {  
		if (!this._dateFormater) {   
			this._dateFormater = new Date();  
		}
		this._dateFormater.setTime(C * 1000);
		var _ = this._dateFormater.getMonth() + 1,  D = this._dateFormater.getDate(),  A = this._dateFormater.getHours(),  B = this._dateFormater.getMinutes();
		return this._dateFormater.getFullYear() + "-" + (String(_).length < 2 ? "0" + _: _) + "-" + (String(D).length < 2 ? "0" + D: D) + " " + (String(A).length < 2 ? "0" + A: A) + ":" + (String(B).length < 2 ? "0" + B: B);
	}, 
	dateDiff: function(B, A) {
		var _ = 24 * 60 * 60 * 1000,  C = B + _ * 10 - parseInt(A);
		return Math.max((C / _).toFixed(0), 0);
	},
	encodeHTML: function(_) {
		return String(_).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
	}
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章