0

I encounter a problem where I could not get the new Date() because the date it's in JSON format. This code is done using MVC C#. The date is in \/Date(1531364413000)\/. The date in the database is in yy-mm-dd Can I change the format in the controller or in the web config? Anybody knows how do I change the default date into JavaScript format?

str
  • 42,689
  • 17
  • 109
  • 127
Rod
  • 61
  • 1
  • 10
  • Like https://stackoverflow.com/questions/18820896/convert-datetime-to-json-datetime or https://stackoverflow.com/questions/11757757/json-datetime-issue ? – str Sep 28 '18 at 07:03
  • There is no "JSON format". You can specify a pattern or format in your schema to validate against though. – RobG Sep 28 '18 at 07:08
  • nope. I want to make the Javascript date format default. I'm using Model-View-Controller – Rod Sep 28 '18 at 07:09
  • What do you consider the "date format default"? – str Sep 28 '18 at 07:09
  • so that it will be able to change it automatically without adding a class to it – Rod Sep 28 '18 at 07:12
  • What do you call "JavaScript format"? The value can be converted to an ECMAScript date usng `new Date(1531364413000)`, though you must ensure you convert it to number first. You can use various methods to extract the time value from the string. – RobG Sep 28 '18 at 07:18

1 Answers1

1

You can create helper javascript function like this

function (date) {
     if (!date)
          return "";
     var dtStart = new Date(parseInt(date.substr(6)));
     var dtStartWrapper = moment(dtStart);
     return dtStartWrapper.format('DD/MM/YYYY');
}

It uses Moment Js

Tech Yogesh
  • 427
  • 4
  • 18