Converts a DateTime to and from a JavaScript date constructor (e.g. new Date(52231943)).
Inheritance: JsonConverter
        public JsonNetSerializer()
        {
            _settings = new JsonSerializerSettings();

            //var customResolver = new CustomIgnoreResolver
            //    {
            //        DefaultMembersSearchFlags = BindingFlags.Instance | BindingFlags.Public
            //    };
            //_settings.ContractResolver = customResolver;

            var javaScriptDateTimeConverter = new JavaScriptDateTimeConverter();

            _settings.Converters.Add(javaScriptDateTimeConverter);
            _settings.Converters.Add(new EntityKeyMemberConverter());
            _settings.Converters.Add(new KeyValuePairConverter());
            _settings.Converters.Add(new ExpandoObjectConverter());
            _settings.Converters.Add(new XmlNodeConverter());

            _settings.NullValueHandling = NullValueHandling.Include;
            _settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
            _settings.TypeNameHandling = TypeNameHandling.Objects;
            _settings.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor;
        }
        public void DeserializeDateTime()
        {
            JavaScriptDateTimeConverter converter = new JavaScriptDateTimeConverter();

              DateTime result = JavaScriptConvert.DeserializeObject<DateTime>("new Date(976918263055)", converter);
              Assert.AreEqual(new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Utc), result);
        }
    public void SerializeDateTimeOffset()
    {
      JavaScriptDateTimeConverter converter = new JavaScriptDateTimeConverter();

      DateTimeOffset now = new DateTimeOffset(2000, 12, 15, 22, 11, 3, 55, TimeSpan.Zero);
      string result;

      result = JsonConvert.SerializeObject(now, converter);
      Assert.AreEqual("new Date(976918263055)", result);
    }
    public void SerializeDateTime()
    {
      JavaScriptDateTimeConverter converter = new JavaScriptDateTimeConverter();

      DateTime d = new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Utc);
      string result;

      result = JsonConvert.SerializeObject(d, converter);
      Assert.AreEqual("new Date(976918263055)", result);
    }
        public void DeserializeDateTimeOffset()
        {
            JavaScriptDateTimeConverter converter = new JavaScriptDateTimeConverter();
              DateTimeOffset start = new DateTimeOffset(2000, 12, 15, 22, 11, 3, 55, TimeSpan.Zero);

              string json = JavaScriptConvert.SerializeObject(start, converter);

              DateTimeOffset result = JavaScriptConvert.DeserializeObject<DateTimeOffset>(json, converter);
              Assert.AreEqual(new DateTimeOffset(2000, 12, 15, 22, 11, 3, 55, TimeSpan.Zero), result);
        }
 public static JsonConverter GetDefaultDateTimeConverter() {
     string dateFormat = GetConfiguration().DateFormat;
     JsonConverter converter;
     switch (dateFormat.ToLower()) {
         case "js":
         case "javascript":
             converter = new JavaScriptDateTimeConverter();
             break;
         case "iso":
             converter = new IsoDateTimeConverter();
             break;
         default:
             converter = null;
             break;
     }
     return converter;
 }
    public void SerializeNullableDateTimeClass()
    {
      NullableDateTimeTestClass t = new NullableDateTimeTestClass()
      {
        DateTimeField = null,
        DateTimeOffsetField = null
      };

      JavaScriptDateTimeConverter converter = new JavaScriptDateTimeConverter();

      string result;

      result = JsonConvert.SerializeObject(t, converter);
      Assert.AreEqual(@"{""PreField"":null,""DateTimeField"":null,""DateTimeOffsetField"":null,""PostField"":null}", result);

      t = new NullableDateTimeTestClass()
      {
        DateTimeField = new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Utc),
        DateTimeOffsetField = new DateTimeOffset(2000, 12, 15, 22, 11, 3, 55, TimeSpan.Zero)
      };

      result = JsonConvert.SerializeObject(t, converter);
      Assert.AreEqual(@"{""PreField"":null,""DateTimeField"":new Date(976918263055),""DateTimeOffsetField"":new Date(976918263055),""PostField"":null}", result);
    }