Skip to content

Instantly share code, notes, and snippets.

@georgehemmings
Last active March 21, 2016 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgehemmings/42d9841913d1da01e91b to your computer and use it in GitHub Desktop.
Save georgehemmings/42d9841913d1da01e91b to your computer and use it in GitHub Desktop.
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