Hello

Hello,

Is there a way to serialize to JSON a TDate and a TTime in a format like "yyyy-mm-dd" and "hh:mm:ss" instead of integer and double values ? TDatetime doesn't have such issue (I don't want to modify my TDate and TTime fields to string type)


type
TTest = class(TObject)
private
public
datetime : TDateTime;
date: TDate;
heure: TTime;
end;
....

Begin
var
Test: TTest;
begin
Test := TTest.Create();
Test.datetime := StrToDate('26/02/2015 10:10:50');
Test.date := StrToDate('26/02/2015'); // french reg. settings
Test.heure := StrToTime('10:10:50');
Memo1.text := TJson.ObjectToJsonObject(Test, [joDateFormatISO8601]).ToJSON;
Test.free;
End;


TJson.ObjectToJsonObject will generate

{"date":42061,"heure":0.424189814814815,"datetime":""2015-02-26T10:10:50.000Z"}

How can I get something like this
{"date":"2015-02-26","heure":"10:10:50.000Z",,"datetime":""2015-02-26T10:10:50.000Z"}
http://Test.fr

Comments