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

New Post: Passing DateTime from c# to javascript function

0
0
Hi!

Thank you for the solution,

So, suppose that my fonction return javascript Date object, and I want to convert it to DateTime object (c#) :
var engine = new V8ScriptEngine();
engine.Execute(@"
    function my_func(props) {
                    var m_date = props.my_date;
                    var m_code = props.my_code;
                    var nextMonth = m_date.getMonth() + 1;
                    m_date.setMonth(nextMonth);
                    return  m_date;
                }
");
var properties = new PropertyBag();
properties["my_code"] = 20;
properties["my_date"] = DateTime.Now.ToJsDate(engine);
dynamic result = engine.Script.my_func(properties);
var  nextMonth = new DateTime(result.getFullYear(), result.getMonth() + 1, result.getDate(), result.getHours(), result.getMinutes(), result.getSeconds());
Is this is a good approach? or Is there an alternative way?

thanks in advance!

kind regard,

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images