0

I am trying to use an html input field with the following code:

<td><input style="width: 80px" type="time" placeholder="HH:MM" required="" data-bind="value: FirstManifest"></td>

The backend C# object containing the FirstManifest property (DateTime?) is populated correctly but when I bind it to a knock view model, the property in the model FirstManifest looks like this

"/Date(1464748440000)/"

How can I convert this so my input only shows the datetime format HH:MM?

wakthar
  • 720
  • 1
  • 8
  • 21
  • Can you write your C# code? Have you read this: http://stackoverflow.com/questions/18016718/using-knockout-js-how-do-bind-a-date-property-to-a-html5-date-picker#18058410 Thank you. – Raspberryano Jun 01 '16 at 14:05

2 Answers2

1

It gets converted to milliseconds.Try converting it back like this.

var oldDate= "/Date(1464748440000)/";
var newDate = new Date(parseInt(oldDate.substr(6)));
document.write(newDate);
   
Vibhesh Kaul
  • 2,593
  • 1
  • 21
  • 38
1

This is how .NET serializes it DateTime i believe. You first need to convert it to JavaScript Date and then get the time element, e.g.

var manifest 
  = new Date(parseInt("/Date(1464748440000)/".replace("/Date(", "").replace(")/",""), 10));

this.FirstManifest = ko.computed(function() {
    return manifest.toLocaleTimeString();
}, this);

you will also need the write part of the computed to convert back from the input to date for persisting to the server.

Ruslan
  • 9,927
  • 15
  • 55
  • 89