javascript 把时间戳转为时间 ajax HTML拼装

时间:2023-03-09 10:04:01
javascript 把时间戳转为时间 ajax HTML拼装

这个目的是记下来,好让我以后可以看一下,这个脚本可是反反复复写了我N天啊!!

全部写下,以备后用!

Date.prototype.format = function(format) {
var o = {
"M+" : this.getMonth() + 1, // month
"d+" : this.getDate(), // day
"h+" : this.getHours(), // hour
"m+" : this.getMinutes(), // minute
"s+" : this.getSeconds(), // second
"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
"S" : this.getMilliseconds()
// millisecond
} if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "")
.substr(4 - RegExp.$1.length));
} for ( var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
: ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
} /**
* ajax刷新竞价数据
*
* @param code
* @return
*/
function QuoteList(code) {
$.ajax({
type : 'POST',
url : appServer + "/tradingCenter/rntrustAllList.htm",
dataType : "json",
data : {code : code},
// data : "projectCode=" + code + "&reason=" + reason,
async : false,
success : function(msg) {
// var resultCollection = jQuery.parseJSON(msg.d);
var htmlhead = '<div class="bd"><div class="listBox"><div> <table style="width:100%;"><tr style="height:20px;"><th>委托号名</th><th>委托价格(元/吨)</th><th>委托数量(吨)</th><th>委托时间</th><th>委托状态</th></tr>';
var content_html="";
var content_htmltemp = "";
var htmlfoot = "</table></div></div></div>"; var entrustPrice = '0.0';
var entrustAmount = '0.000'; var resultInfo = $("#resultInfo");
$.each(msg, function (index, item) { var Datetemp= new Date(item.gmtEntrust);// 这里必须是整数,毫秒
var dateStr = Datetemp.format("yyyy-MM-dd hh:mm:ss");
// alert(dateStr);
content_htmltemp = "<tr>"
+ "<td align='center'>" + item.entrustNo + "</td>"
+ "<td align='center'>" + item.entrustPriceDes + "</td>"
+ "<td align='center'>" + item.entrustAmountDes + "</td>"
+ "<td align='center'> " + dateStr + "</td>"
+ "<td align='center'>" + item.entrustStatusDes + "</td>"
+ "</tr>";
content_html = content_html + content_htmltemp;
entrustAmount = (parseFloat(entrustAmount) + parseFloat(item.entrustAmountDes)); if (parseFloat(item.entrustPriceDes) > parseFloat(entrustPrice)){
entrustPrice = item.entrustPriceDes;
} });
resultInfo.html(htmlhead + content_html + htmlfoot); //价格和数量
if(entrustPrice == '0.0'){
$("#entrustPrice").text("无人报价");
$("#entrustAmount").text("0");
}else{
$("#entrustPrice").text(entrustPrice);
$("#entrustAmount").text(entrustAmount);
}
},
error : function() {
// alert("服务器忙,请稍后重试");
}
});
}