Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Passing DateTime from c# to javascript function

$
0
0
Hi!

I want to pass DateTime from C# code to javascript function and use it as javascript Date object
my sample code :
V8ScriptEngine engine = new V8ScriptEngine();
engine.Execute("function my_func(props){ var m_date  = props[\"my_date\"]; var m_code = props[\"my_code\"];  var yeay = m_date.getFullYear(); }");
PropertyBag properties = new PropertyBag();
HostFunctions hostObj = new HostFunctions();
hostObj.setProperty(properties, "my_code", 20);
hostObj.setProperty(properties, "my_date", DateTime.Now);
dynamic result = engine.Script["my_func"](properties);
An exception was thrown: TypeError: m_date.getFullYear is not a function

How can I fix it ?

kind regard,

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>