Reputation: 338
I'm uses SuperObject library for work with JSON.
I have this JSON(part of Mozilla FireFox, Chrome Bookmarks file):
"roots": {
"bookmark_bar": {
"children": [ {
"date_added": "13009663942000000",
"id": "11",
"meta_info": "{\"sync\":{\"transaction_version\":\"3\"}}",
"name": "\u041D\u0430\u0447\u0430\u043B\u044C\u043D\u0430\u044F \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0430",
"type": "url",
"url": "http://www.mozilla.com/ru/firefox/central/"
}, {
I tried use function JavaTimeToDelphiDateTime with data as integer, but it doesn't work.
I need read "date_added" field as TDateTime. How to do that, using SuperObject library?
Upvotes: 1
Views: 2917
Reputation: 338
The solution:
function JavaTimeToDateTime(javatime:Int64):TDateTime;
// java time -> Win32 file time -> UTC time
// adjust to active time zone -> TDateTime
var
UTCTime, LocalTime: TSystemTime;
begin
FileTimeToSystemTime(TFileTime(Int64(javatime + 11644473600000) * 10000), UTCTime);
SystemTimeToTzSpecificLocalTime(nil, UTCTime, LocalTime);
Result := SystemTimeToDateTime(LocalTime);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//13009663942000000 is the value, read from "date_added" field as Int64.
ShowMessage(DateTimeToStr(JavaTimeToDateTime((13009663942000000 div 10000))));
end;
Upvotes: 3