I am trying to pass a datetime from C# to javascript.
I have converted my datetime at C# to FileTime (I am not sure, if this is the way to be done), and after that I passed this value to a ViewBag like this.
ViewBag.minDate = minDate.ToFileTime();
Next I do this at javascript
var date = new Date(Date.parse(<%=ViewBag.minDate%>));
Which becomes the following, but I get "Invalid Date"
var date = new Date(Date.parse(130014720000000000)
Do you know why is that, and How I can fix it?
Try this:
ViewBag.minDate = minDate.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
pass the date like this,
ViewBag.minDate =minDate.ToString("o")
and in your view,
var date = new Date("<%=ViewBag.minDate %>")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With