Convert Data generated in C # to ISO format in Javascript

2

Hello, I'm doing a website where I use an API built in C #. My problem is that when I get a date from the server, it sends me that format:

[{
    "dataLiberacao":"\/Date(928160400000-0300)\/",
    "dataReg":"\/Date(928160400000-0300)\/",
    "id":2147483647,
    "maquina":"Conteúdo da cadeia de caracteres",
    "status":true,
    "versao":"Conteúdo da cadeia de caracteres"
}]

I need to know how to convert this into a common format for Javascript.

NOTE: I have tried with the API staff to send this to me in string but unfortunately they will not change the project so ...

    
asked by anonymous 21.11.2016 / 14:02

1 answer

2

Download momentjs which is a library #, which works with various date formats and various functions:

moment("/Date(1198908717056-0700)/").format('DD/MM/YYYY'); 

var data = moment("/Date(1198908717056-0700)/").format('DD/MM/YYYY'); 
console.log(data);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.16.0/moment-with-locales.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>

In your case it would be something:

moment(dataLiberacao).format('DD-MM-YYYY');

Another way:

With eval and new Date :

var data = eval('new Date(1198908717056-0700)');
console.log(data.toLocaleString());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Thetwowaysarefunctional, momentjs is a library

References:

21.11.2016 / 14:13