1

I am having problem in binding datetime in beatpicker while fetching data from the database. In the picker it renders as: "/Date(1465323300000)/" , the KOJS as:

DematRenounced.js

 if (obj.ResponseData != null) {
                                                 if (obj.ResponseData.length > 0) {
                                                     var DematRenouncedEntry = obj.ResponseData[0];
                                                     
                                                     self.entrydate(DematRenouncedEntry.entrydate);
                                               
                                             }

and View as:

DematRenouncedEntry.aspx

  <input type="text" id="txtEntryDate" data-beatpicker="true" class="form-control"
                                        data-bind="value:entrydate" maxlength="10" onblur="return valFutureDate(this,'Y',true);"
                                        onpaste="return false" onkeypress="return isNumberKey(event)"
                                        placeholder="YYYY.MM.DD" />
Community
  • 1
  • 1
  • http://everythingjs.blogspot.co.uk/2012/03/json-dates-and-knockoutjs-date-binding.html ..basically uses regular expression to parse the date and then convert to dd-MM-yyyy format. – Rohith Nair Jun 08 '16 at 10:09

3 Answers3

2

The data returned from the server is apparently serialized using Microsoft JsonSerializer that uses a non-standard format when serializing DateTime properties. See this answer for more details: https://stackoverflow.com/a/726869/4602079.

What you need to do before you can do anything with the date on the client is to parse it as Date. In your case you could modify DematRenounced.js as follows:

self.entrydate(new Date(parseInt(DematRenouncedEntry.entrydate.replace("/Date(", "").replace(")/",""), 10)));
Community
  • 1
  • 1
Maciej Grzyb
  • 543
  • 2
  • 10
0

Following Maciej Grzyb's answer, Finally I got solution.

   var t = new Date(parseInt(DematRenouncedEntry.entrydate.replace("/Date(", "").replace(")/", ""), 10));

                                             var m = t.getMonth();
                                             var d = t.getDate();
                                             function addZ(m) { return m < 10 ? '0' + m : '' + m; };
                                             function addZy(d) { return d < 10 ? '0' + d : '' + d; };
                                             var y = t.getFullYear();
                                             var format = y + "." + addZ(m) + "." + addZy(d);
                                             self.entrydate(format);
0

I'd check out this: https://stackoverflow.com/a/18555136/1455010

Change the Json converter to format the date in ISO format: 2016-06-16T18:52:36+00:00

Community
  • 1
  • 1
Nate
  • 650
  • 3
  • 7