Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date from javascript to C# is not working

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?

like image 760
Jim Blum Avatar asked Jun 11 '26 13:06

Jim Blum


2 Answers

Try this:

ViewBag.minDate = minDate.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
like image 50
anar khalilov Avatar answered Jun 14 '26 02:06

anar khalilov


pass the date like this,

ViewBag.minDate =minDate.ToString("o")

and in your view,

var date = new Date("<%=ViewBag.minDate %>")
like image 37
Mat J Avatar answered Jun 14 '26 01:06

Mat J