摘录:①"AddTime":"\/Date(1448002115000)\/" 对应数据库类型:datetime
②"SetOutTime":"\/Date(1448490000000)\/" 对应数据库类型:time(7)
③"SetOutDate":"\/Date(1448035200000)\/" 对应数据库类型:date
问题:如何变成自己要的时间格式?
全文:
{"TotalCount":4,"PageData":[{"BusNumber":"豫AP1102","Type":"豪华大巴","Capacity":45,"RunningState":0,"LineNumber":"XL20151119022357","Name":"郑州至南阳","StartingCity":"郑州","EndCity":"南阳","StartingStation":"郑州中心站","EndStation":"南阳","Id":"590fd8af-d45b-476e-b","SetOutTime":"\/Date(1448490000000)\/","SetOutDate":"\/Date(1448035200000)\/","SalesVolume":0,"MotorcoachNumber":"6818","AddTime":"\/Date(1448002115000)\/","SoldOut":false,"State":1,"TicketPrice":100.0,"Mileage":0},{"BusNumber":"豫AP1106","Type":"豪华商务","Capacity":20,"RunningState":1,"LineNumber":"XL20151119022357","Name":"郑州至南阳","StartingCity":"郑州","EndCity":"南阳","StartingStation":"郑州中心站","EndStation":"南阳","Id":"2a25fc9e-c444-4d6f-a","SetOutTime":"\/Date(1448502600000)\/","SetOutDate":"\/Date(1448035200000)\/","SalesVolume":0,"MotorcoachNumber":"6804","AddTime":"\/Date(1448070115000)\/","SoldOut":false,"State":1,"TicketPrice":100.0,"Mileage":0}],"PageContent":"\u003ca href=\"javascript:;\" class=\"up-page\"\u003e上一页\u003c/a\u003e\u003ca class=\"cur\"\u003e1\u003c/a\u003e\u003ca href=\"/Scheduling/PartialTickets?lineNumber=XL20151119022357\u0026date=2015-11-21\u0026page=2\"\u003e2\u003c/a\u003e\u003ca href=\"/Scheduling/PartialTickets?lineNumber=XL20151119022357\u0026date=2015-11-21\u0026page=2\" class=\"down-page\"\u003e下一页\u003c/a\u003e\u003cspan\u003e共\u003cstrong\u003e4\u003c/strong\u003e页\u003cinput type=\"text\" id=\"txtGoto\" value=\"1\" class=\"txt\"\u003e页\u003cinput type=\"button\" class=\"btn-bg\"\u003e\u003c/span\u003e"}
\/Date(1448002115000)\/
提取下数字部分:1448002115000
这个数字是unix 时间戳。
如果想在 js 上处理这个 就可以 var time= new Date(1448002115000 ) 得到这个Date 对象
如果是在服务器端处理的话,可以自己搜下 C# 处理 unix 时间戳
谢谢,var time= new Date(1448002115000 ) 这样是可以的,非常感谢
也就是说,json串中的时间数据需要转化为数据库中对应的类型?需要什么语言?
不是的,
for (var i = 0; i < _pageData.length; i++) {
_html += "<tr class='content'><td><input type=\"checkbox\" class=\"chk\" /> <input type=\"hidden\" value=\"" + _pageData[i].id + "\" id=\"" + i + "\"/></td><td>" + _pageData[i].MotorcoachNumber + "</td><td>" + _pageData[i].BusNumber + "</td><td>" + _pageData[i].StartingStation + "</td><td>" + _pageData[i].EndStation + "</td><td>" + _pageData[i].SetOutTime + "</td>" + "<td><span class=\"edit\" >修改</span><span class=\"delete\">删除</span></td></tr>";
}
问题点:_pageData[i].SetOutTime 只需要这个能显示时间就可以了,现在没办法,我把数据类型改成varchar(10),c# 时间类型是datetime
@我想啸天: 其他的可以显示吗?
如果用的是json.net组件的话,那么在序列化的时候,可以指定序列化的格式,如下
IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
var str= JsonConvert.SerializeObject(obj, Newtonsoft.Json.Formatting.Indented, timeFormat);