Отображение даты в правильном формате

c# jquery asp.net asp.net-mvc

78 просмотра

2 ответа

97 Репутация автора

У меня есть такая строка. Как мы можем показать дату в правильном формате? Теперь это выглядит так: «Дата теста»: «/ Дата (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);
};    

Можем ли мы сделать что-нибудь, чтобы получить дату в правильном формате в этой строке?

Автор: Dev Try Источник Размещён: 18.07.2016 08:51

Ответы (2)


1 плюс

34 Репутация автора

Предполагая, что это Javascript getTime милисекунды:

var time = 1468783153887;
var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
    .AddMilliseconds(time)
    .ToLocalTime();

Впоследствии переменная dateTime выглядит так: 17.07.2016 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

Автор: Christof Mehlstäubler Размещён: 18.07.2016 09:12

0 плюса

38759 Репутация автора

Используйте это, чтобы конвертировать

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);

Автор: naveen Размещён: 12.08.2016 02:58
Вопросы из категории :
32x32