var Common = {};
1.格式化时间 yyyy-MM-dd hh:mm:ss; 方法 getDateTime(),参数 date , format
---1 通过Date()对象的方法可以获取 年月日和时间,在把获取到的值通过 format.replace("XX")替换对应的格式;
2.计算两个时间的距离 ,startTime,endTime,返回 day,time=小时:分钟:秒
<span style="white-space:pre"> </span>try{
var ms = endTime - startTime;
var day = parseInt(ms/24/60/60/1000);
var ms_sum = ms-day*24*60*60*1000;
var minute_sum = ms_sum/1000/60;
var hour = parseInt(minute_sum/60);
var minute = parseInt(minute_sum-(hour*60));
var seconds = parseInt(((ms_sum%24)%60));
return {
day:day,
time:hour+":"+minute+":"+seconds
}
}
catch(e){
alert("error: "+e.message);
}
3.apiCall() 用$.ajax方法请求,参数(options,callback,errorCallback),options为一般的AJAX的配置,callback为成功请求时调用的函数,
errorCallback为请求错误时调用的方法
----1 定义defaults 默认配置 (url,type,data,dataType,async,cache)
----2 var ajaxOptions = $.extend(default,options);
----3 成功时调用callback
<span style="white-space:pre"> </span>ajaxOptions["success"] = function(result){
try {
callback(result);
} catch (e) {
alert("We've encountered some problems. Please try again or refresh the page.");
}
};
----4 失败时调用errorCallback
<span style="white-space:pre"> </span>ajaxOptions["error"] = function(result){
try {
var jsonObj = JSON.parse(result.responseText);
console.log(jsonObj.errorMessage);
if(typeof errorCallback != 'undefined'){
errorCallback(jsonObj);
} else {
alert(jsonObj.errorMessage);
}
} catch (e) {
alert("We've encountered some problems. Please try again or refresh the page.");
console.log(result.responseText);
}
};
4.message:文字提示窗口
5.popup确定窗口
-------------------------------------------------------------
Common.getDateTime
Common.getTimeDiff
Common.apiCall
Common.message
Common.popup