我使用SuperObject库来处理JSON。
我有这个JSON(Mozilla FireFox的一部分,Chrome书签文件):
"roots": {
"bookmark_bar": {
"children": [ {
"date_added": "13009663942000000",
"id": "11",
"meta_info": "{"sync":{"transaction_version":"3"}}",
"name": "u041Du0430u0447u0430u043Bu044Cu043Du0430u044F u0441u0442u0440u0430u043Du0438u0446u0430",
"type": "url",
"url": "http://www.mozilla.com/ru/firefox/central/"
}, {
我尝试使用函数JavaTimeToDelphiDateTime将数据作为整数,但它不起作用。
我需要读取"date_added"字段作为TDateTime。如何使用超级对象库来做到这一点?
解决方案:
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;