我正在调用我的服务器代码来返回json数据
$.ajax({
type: "POST",
url: "myurl",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (appdata) {
var testdata = $.parseJSON(appdata.d);
console.log(testdata);
$.each(testdata, function (index, appt) {
//console.log(appt.PRODUCTID);// works fine
//console.log(appt.ENTRYDATE);// works fine
// var starttime=??
}
});
这是console.log(testdata)
输出
[Object, Object]
0: Object
PRODUCTID : "51",
ENTRYDATE : "2013-02-13T12:30:00",
CATEGORYID : null
__proto__:Object
1: Object
PRODUCTID : "52",
ENTRYDATE : "2013-02-13T12:40:00",
CATEGORYID : null
__proto__: Object
length: 2
__proto__: Array[0]
如何从第一个对象的入围日期2013-02-13T12:30:00
修改
console.log(appt.ENTRYDATE)
运行正常,问题只是如何从appt.ENTRYDATE
答案 0 :(得分:2)
您可以使用javascript split
提取时间信息 var datetime = appt.ENTRYDATE;
var datedata = datetime.split("T");
var datevalue = datedata[0]; //date value
var timevalue = datedata[1]; //time value
答案 1 :(得分:1)
How can I extract the time information from ENTRYDATE like (12:30)
$.each(testdata, function (index, appt) {
var $getTime = appt.ENTRYDATE;// works fine
var $Time = $getTime.substr($getTime.indexOf('T')+1).slice(0, -3);
console.log($Time); // output will be: 12:30, 12:40
});
答案 2 :(得分:1)
这可能是最糟糕的答案,但您可以尝试拆分
var starttime="2013-02-13T12:40:00"; // this comes from appt.ENTRYDATE
var n=starttime.split("T");
console.log(n[1]);