html 表单赋值 和 时间戳 转换
<script> window.onload = function () { var str; // console.log(@ViewBag.ID); $.post("/ServiceBills/ServiceBills/UpdateA", { id: @ViewBag.ID}, function (data) { //console.log(data); //console.log("1222222"); //$("form").setForm(data); for (var attr in data) { //console.log(attr);//name,age,gender // console.log(data[attr]);//jack,25,male //值 //console.log(typeof json1[attr]); // $("#" + attr).val("111111111"); $("#" + attr).val(data[attr]); //id if ((data[attr] + "").indexOf("/Date(") != -1) { //时间 str = data[attr] + ""; str = timestampToTime(str.substring(6, str.length - 2)); // console.log(str); } else { str = data[attr]; } $("input[name='" + attr + "']").val(str); //输入框 } }); // console.log("12132"); @*$.post("/ServiceBills/ServiceBills/UpdateA",{ id=@ViewBag.ID}, function (data) { console.log(data); //$("form").setForm(data); });*@ } function timestampToTime(timestamp) { ///Date(1514736000000)/ var date = new Date(timestamp * 1);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 Y = date.getFullYear() + '-'; M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; D = date.getDate() + ' '; h = date.getHours() + ':'; m = date.getMinutes() + ':'; s = date.getSeconds(); return Y + M + D + h + m + s; } //timestampToTime(); console.log(timestampToTime(1514736000000));//2014-06-18 10:33:24 </script>