0

here is my situation. From the server (written in C#), I pass a DateTime object to client using JSON, then I try to display it using jqGrid. However, the date keep displaying like /Date(1430413200000+0700)/. I want it to be m/d/Y. Here is my code:

            colModel: [
                {
                    name: 'MyDate',
                    index: 'MyDate',
                    formatter: 'date',
                    formatoptions: {
                        srcformat: "ISO8601Long",
                        newformat: "m/d/Y h:i A"
                    }
                }
            ]

Thank you for your help!

Triet Doan
  • 11,455
  • 8
  • 36
  • 69
  • What's your server-side technology? I'm assuming MVC. That's the format MVC usually uses to serialize its dates... Check [this question](http://stackoverflow.com/questions/10527001/asp-net-mvc-controller-json-datetime-serialization-vs-newtonsoft-json-datetime-s) and [this one](http://stackoverflow.com/questions/14973286/asp-net-mvc-json-datetime-serialization-conversion-to-utc) too. Scott Hanselman has [a great post](http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx) on this topic. – Andrei V Jul 22 '15 at 06:28
  • I'm using Web Form. I think my problem is the `jqGrid` doesn't format the date data. – Triet Doan Jul 22 '15 at 06:39
  • Regardless of what you're using, the date does not get parsed as you expected. You have then two options: change the date parsing on the server or write a custom APS.Net date format parser in JavaScript: `var value = new Date(parseInt(jsonDate.substr(6)));`. – Andrei V Jul 22 '15 at 07:19
  • which fork of jqGrid and in which version you use? I suppose you use some retro version of jqGrid. In any way you can return ISO date from the server using `.ToString("o")` conversion on the server side or to update jqGrid to [free jqGrid](https://github.com/free-jqgrid/jqGrid) 4.9 for example. – Oleg Jul 22 '15 at 09:17

1 Answers1

1

Try adding actual ISO8601Long format like this

 colModel: [
            {
                name: 'MyDate',
                index: 'MyDate',
                formatter: 'date',
                formatoptions: {
                    srcformat: "'Y-m-d H:i:s",
                    newformat: "m/d/Y h:i A"
                }
            }
        ]