1

I am trying to convert some data to js so I can use ko arrays. This is how I am doing it in the .cshtml file.

var List = @(Html.Raw(Json.Encode(Model.Item)));

All of the data is correct except for the date. When I display it from Model.Item.Date is comes out to 3/9/2018

But when I display it from List.Date it gives me this weird string /Date(1520582400000)/

What format is this in and how can I convert it?

Thank you for the help.

1 Answer 1

1

The number is milliseconds and you can convert it to a date like this :

var t = new Date().getTime('1520582400000');
var d = new Date(t);
console.log(d.toString());

Sign up to request clarification or add additional context in comments.

2 Comments

This worked! Thank you. Do you know of a better way to pass the date in from c# to js so I wouldn't need to write this extra code to replace the all of the dates? If not its cool, thanks again.
I don't think so but I will look around.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.