Delphi解析JSON日期格式,如何转换为长尾词?

2026-04-10 02:251阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计201个文字,预计阅读时间需要1分钟。

Delphi解析JSON日期格式,如何转换为长尾词?

DELPHI解析JSON格式化的日期+json返回的日期是+/Date(1560355200000)/+这样的格式。这个1560355200000,是1970年后的秒数。DELPHI如何解析这种日期格式?网上找到的多数是JAVASCRIPT的代码,与DELPHI关系不大。

DELPHI解析JSON格式化的日期

json返回的日期是 /Date(1560355200000)/ 这样的格式。

这个1560355200000,是指1970年以后的秒数。

Delphi解析JSON日期格式,如何转换为长尾词?

DELPHI如何解析这种日期格式?

网上找到的多是JAVASCRIPT的代码,没关系,DELPHI可以执行JAVASCRIPT函数。

uses comobj; var js: string= ‘function jsondate(jsonDate) {‘+ ‘try {‘+ ‘var date = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10));‘+ ‘var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;‘+ ‘var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();‘+ ‘var hours = date.getHours();‘+ ‘var minutes = date.getMinutes();‘+ ‘var seconds = date.getSeconds();‘+ ‘var milliseconds = date.getMilliseconds();‘+ ‘return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds + "." + milliseconds;‘+ ‘} catch (ex) {‘+ ‘return "";‘+ ‘}‘+ ‘}‘; function RunJs(const JsCode, JsVar: string): string; var script: OleVariant; begin try script := CreateOleObject(‘ScriptControl‘); script.Language := ‘JavaScript‘; script.ExecuteStatement(JsCode); Result := script.Eval(JsVar); except Result := ‘‘; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Caption := RunJs(js, Format(‘jsondate("%s")‘, [‘/Date(1560355200000)/‘])); end;

  

标签:日期Delphi

本文共计201个文字,预计阅读时间需要1分钟。

Delphi解析JSON日期格式,如何转换为长尾词?

DELPHI解析JSON格式化的日期+json返回的日期是+/Date(1560355200000)/+这样的格式。这个1560355200000,是1970年后的秒数。DELPHI如何解析这种日期格式?网上找到的多数是JAVASCRIPT的代码,与DELPHI关系不大。

DELPHI解析JSON格式化的日期

json返回的日期是 /Date(1560355200000)/ 这样的格式。

这个1560355200000,是指1970年以后的秒数。

Delphi解析JSON日期格式,如何转换为长尾词?

DELPHI如何解析这种日期格式?

网上找到的多是JAVASCRIPT的代码,没关系,DELPHI可以执行JAVASCRIPT函数。

uses comobj; var js: string= ‘function jsondate(jsonDate) {‘+ ‘try {‘+ ‘var date = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10));‘+ ‘var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;‘+ ‘var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();‘+ ‘var hours = date.getHours();‘+ ‘var minutes = date.getMinutes();‘+ ‘var seconds = date.getSeconds();‘+ ‘var milliseconds = date.getMilliseconds();‘+ ‘return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds + "." + milliseconds;‘+ ‘} catch (ex) {‘+ ‘return "";‘+ ‘}‘+ ‘}‘; function RunJs(const JsCode, JsVar: string): string; var script: OleVariant; begin try script := CreateOleObject(‘ScriptControl‘); script.Language := ‘JavaScript‘; script.ExecuteStatement(JsCode); Result := script.Eval(JsVar); except Result := ‘‘; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Caption := RunJs(js, Format(‘jsondate("%s")‘, [‘/Date(1560355200000)/‘])); end;

  

标签:日期Delphi