Reputation: 8283
why my Json DateTime value has T before time.
{
"code": "Code",
"date": "2018-05-02T20:02:24" //T
},
Code inside my web API
public IEnumerable<Result> MethodName()
{
var result = (from x in Context.Tabl1
select new Result
{
Code = x.Code,
Date = x.Date,// I dont want to apply ToString(format)
}).ToArray();
}
Expected Result
{
"code": "Code",
"date": "2018-05-02 20:02:24" //Without T
},
Upvotes: 0
Views: 732
Reputation: 1502756
why my Json DateTime value has T before time.
Because that's what ISO-8601 says to do. There are various options for date/time values in ISO-8601, but all of them use a "T" to separate the date part from the time part. ISO-8601 is probably the most commonly-used format for machine-readable date and time representations as text.
The machine-readable part is important here. JSON is a machine-readable format that's also intended to be reasonable human-readable - like XML. It's not intended to be a format for non-developers to consume directly. Instead, a presentation layer (UI, report generator, whatever it is) is intended to format the underlying data ("a date and time") in the most appropriate representation for the user. That may use am/pm designators, month names, culture-specific formats etc - all of which are good for human consumption, but make machine consumption harder.
I strongly urge you not to move away from ISO-8601 here. That's the most appropriate representation for JSON.
Upvotes: 9