Skip to content

Instantly share code, notes, and snippets.

@georgehemmings georgehemmings/Program.cs
Last active Mar 21, 2016

Embed
What would you like to do?
JsonDates
using System;
using ServiceStack;
using ServiceStack.Text;
namespace JsonDate
{
public class Dates
{
public DateTime DateOnly { get; set; }
public DateTime DateWithTime { get; set; }
}
class Program
{
static void Main(string[] args)
{
var dates = new Dates
{
DateOnly = DateTime.Today,
DateWithTime = DateTime.Now
};
using (JsConfig.With(dateHandler: DateHandler.ISO8601DateOnly))
{
var json = dates.ToJson(); // {"DateOnly":"2016-03-21","DateWithTime":"2016-03-21"}
}
using (JsConfig.With(dateHandler: DateHandler.ISO8601))
{
var json = dates.ToJson(); // {"DateOnly":"2016-03-21T00:00:00.0000000+00:00","DateWithTime":"2016-03-21T12:18:58.8551447+00:00"}
}
// desired json {"DateOnly":"2016-03-21","DateWithTime":"2016-03-21T12:18:58.8551447+00:00"}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.