Return Date object as json data in MVC

Prem Murmu on 10/6/2021 2:09:05 PM

I was working on Sitecore Mvc Jsonresult action method type , trying to return Json date object to AJax call.

I was getting an unknown format of date in return, which was very painful to get the solutin at that time very quickly. I had strict deadline to implement timer or count down timer in a page.

I googled a lot , found different kind of jsondatetime handler used by others, i found them complex. Finally i got the trick and tried, and worked.

My initial Jsonresult action method was:


Which returns date for in json :   /Date(1655718400000)/

I was unble to convert it to proper date format in js/jquery client side.

To overcome this problem i just convert the date object to json object in action method, Like below code

  // Convert the date object to json format

   var response = JsonConvert.SerializeObject(TimerModel.TickerTimer);

Json return: "\"2021-11-11T22:30:00Z\""

Now it is easy to conver this json date covert or deserilize and convert it to a normal date format in client side in javascrit or jQuery.

Let me know if it not works in yourside.


0 Comments on this post

Comments(0)||Login to Comments

InterServer Web Hosting and VPS
  • see more..