-3

I have an issue with date.In my Model class I have used DateTime property(I used Code First), for transferring json data from action to another action I use Jquery ($.ajax), my date convert in this format, I think it milliseconds:

/Date(1188594000000)/

I tryed to convert it using js, not working: var date = new Date(mydate);

5
  • mydate = /Date(1188594000000)/, date = invalid date outputs Commented Feb 6, 2017 at 18:22
  • you don't understand situation Commented Feb 6, 2017 at 18:29
  • I have a c# datetime like this 2017-01-03, passed this date from action to another action using jquery , in my view I get this : /Date(1188594000000)/ instead of 2017-01-03. Commented Feb 6, 2017 at 18:31
  • yes, I find the way. Commented Feb 6, 2017 at 18:39
  • Possible duplicate of ASP.NET MVC JsonResult Date Format Commented Feb 6, 2017 at 21:55

1 Answer 1

1

/Date(1188594000000)/ is a string and the long numbers inside the brackets are the milliseconds since the beginning of the unix epoch time. You cannot pass that(the string as it is) to Date constructor. If you want to generate a datetime object from that value, you should remove the first 6 characters (/Date() and pass the milliseconds only

var mydate='/Date(1188594000000)/';
var dateVal= parseInt(mydate.substr(6));
var dateObj= new Date(dateVal);
console.log(dateObj);

The statement mydate.substr(6) will return a string value like "1188594000000)/" and passing this to parseInt method returns the number 1188594000000 which can be safely passed to the Date constructor.

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

Comments

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.