2

Take a look at the following example code, I would like the output to be a WCF date format "/Date(1237951967000)/" or the time zone variant.

class Program
{
    public class Test
    {
        public DateTime Date { get; set; }
    }

    static void Main(string[] args)
    {
        var test = new Test
            {
                Date = DateTime.Now
            };


        var json = JsonConvert.SerializeObject(test);


        Console.WriteLine(json);
    }
}

Here is the output:

{"Date":"2013-05-09T11:17:38.7990259-07:00"}

How can I adjust the above code to give the desired format?

{"Date":"\/Date(1237951967000)\/"}

1 Answer 1

9
var settings = new JsonSerializerSettings() {DateFormatHandling= DateFormatHandling.MicrosoftDateFormat};
var json = JsonConvert.SerializeObject(test, settings);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.