以正确的格式显示日期
本文关键字:显示 日期 格式 | 更新日期: 2023-09-27 17:57:20
我有这样的字符串。我们如何以正确的格式显示日期?现在它像这样显示:"测试日期":"/日期(1468783153887)/"。我在 jquery 函数中分配字符串值:
[{"RowIndex":1,"ObjectId":600290,"SpaceId":null,"Xposition":null,"Yposition":null,"Angle":null,"DrawingId":18137,"BlockRefHandle":"3DE","ObjectClassId":9387,"SymbolId":null,"ScaleFactor":null,"SymbolColor":120,"IsBlockBased":true,"NumberWithClassName":"DR-1040318 (Doors)","ObjectNo":"DR-1040318","ObjectClassName":"Doors","Equipment":"Doors","Address":"123:7yt","NFPA Classification":null,"Health Classification":null,"Test Method":"Functional","Test Result":"Passed","Test Date":"'/Date(1468783153887)'/","Dev. Reading":null,"Dev. Reading Date":"'/Date(1468783153887)'/","Barcode":null,"Site":"4433-75006-00045","Building":"Building Test","Floor":"Floor Test","Status":"Assigned","Attachments":"None","sfde":null,"Attribute for test - not mand":null,"Attribute for test":null,"Test Attribute":null,"intsi":null,"uiiiiiii":null,"Note":null,"s667":null,"sg":null,"ui":null,"My Attribute":null,"Comment":null,"Comments":null,"Location":null,"test12":null,"abcd":null,"Activate1":null,"Activating":null,"Activating Device Address":null,"Activating Device Location":null,"Shutdown Device Type":null,"Test2":null,"vvvd":null}]
功能
function toolTipFulldata(i, columnAlias) {// building contents to tooltip
var html = '';//'<table border="1">';
$.each(dataForToolTip[i], function (key, value) {
for (var j = 0; j < columnAlias.length; j++) {
if (key == columnAlias[j]) {
if (value == null)
value = "";
html += '<span>' + key + '</span>';
html += '<span style="color:blue;">' + ":" + value + '</span></br>';
}
}
});
$("#showTooltip").html(html);
};
我们可以做任何事情来获取该字符串中正确格式的日期吗?
假设这些是Javascript getTime毫秒:
var time = 1468783153887;
var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
.AddMilliseconds(time)
.ToLocalTime();
之后,可变日期时间如下所示: 2016-07-17 21:19:13
要将 JSON 解析为数组,请执行以下操作:
var jsonString = @"[{""RowIndex"":1,""ObjectId"":600290,""SpaceId"":null,""Xposition"":null,""Yposition"":null,""Angle"":null,""DrawingId"":18137,""BlockRefHandle"":""3DE"",""ObjectClassId"":9387,""SymbolId"":null,""ScaleFactor"":null,""SymbolColor"":120,""IsBlockBased"":true,""NumberWithClassName"":""DR-1040318 (Doors)"",""ObjectNo"":""DR-1040318"",""ObjectClassName"":""Doors"",""Equipment"":""Doors"",""Address"":""123:7yt"",""NFPA Classification"":null,""Health Classification"":null,""Test Method"":""Functional"",""Test Result"":""Passed"",""Test Date"":""'/Date(1468783153887)'/"",""Dev. Reading"":null,""Dev. Reading Date"":""'/Date(1468783153887)'/"",""Barcode"":null,""Site"":""4433-75006-00045"",""Building"":""Building Test"",""Floor"":""Floor Test"",""Status"":""Assigned"",""Attachments"":""None"",""sfde"":null,""Attribute for test - not mand"":null,""Attribute for test"":null,""Test Attribute"":null,""intsi"":null,""uiiiiiii"":null,""Note"":null,""s667"":null,""sg"":null,""ui"":null,""My Attribute"":null,""Comment"":null,""Comments"":null,""Location"":null,""test12"":null,""abcd"":null,""Activate1"":null,""Activating"":null,""Activating Device Address"":null,""Activating Device Location"":null,""Shutdown Device Type"":null,""Test2"":null,""vvvd"":null}]";
var j = JArray.Parse(jsonString);
var date = j[0]["Test Date"];
Console.WriteLine(date);
输出此内容: 17/07/2016 19:19:13
使用它来转换
var returned_date_string = "/Date(1468783153887)/";
var milli_seconds = /'d+/.exec(returned_date_string)[0];
console.log(milli_seconds);
var returned_date = new Date(+milli_seconds);
console.log(returned_date);