JsonDates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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