passing DateTime to Jurassic

Nov 29, 2012 at 1:58 PM

How do I pass .NET DateTime object to Jurassic so that it can be manipulated as Javascript Date object?

Coordinator
Nov 30, 2012 at 12:41 AM
Edited Nov 30, 2012 at 12:42 AM

 There's no built-in way to do this, but it's not so hard:

DateTime dt = ...;  // Your .net date.
ScriptEngine scriptEngine = ...; // Your script engine.

// We need to pass in the number of milliseconds since 1 January 1970 00:00:00 UTC. var myJSDate = scriptEngine.Date.Construct(dt.ToUniversalTime().Subtract(
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds);