XML日期和时间采用格式
' - '?yyyy' - 'mm' - 'dd'T'hh':'mm':'ss('.'s +)?(ZZZZZZ)?
是
• ' - '?yyyy是一个四位或更多数字的可选负数字,代表年份; 如果超过四位数,则禁止前导零,并禁止"0000"
•剩余的' - 是日期部分之间的分隔符;
•第一个mm是表示月份的两位数字;
•dd是代表日期的两位数字;
•'T'是一个分隔符,表示随后的时间;
•hh是一个代表小时的两位数字; 如果表示的分钟和秒为零,则允许"24",并且如此表示的dateTime值是第二天的第一个时刻(·值空间中的dateTime对象的小时属性·不能具有大于23的值) ;
•':'是时间部分的部分之间的分隔符;
•第二个mm是一个两位数的数字,表示分钟;
•ss是一个两位整数的数字,表示整秒;
•'.s +(如果存在)代表小数秒;
•zzzzzz(如果存在)表示时区(如下所述).
这里有更多的例子
简单示例 2009-08-31T19:30:00
更复杂的例子
2002-10-10T12:00:00-05:00(2002年10月10日中午,中部夏令时以及美国东部标准时间)是2002-10-10T17:00:00Z,比2002年晚5个小时-10-10T12:00:00Z.
有关详细信息,请参阅www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html
我从请求中收到以下 JSON:
{
"cdPlayer": 3,
"nmPlayer": "Player Name",
"dtCreate": "2016-08-24T22:53:31.687",
"dtChange": null,
"idStatus": true
}
Run Code Online (Sandbox Code Playgroud)
我想加载转换 dtCreate 和 dtChange 到 TDateTime。如何正确地做到这一点?没有TJSONDateTime可以投射的GetValue。下面是我当前的代码,我将其转换为纯字符串。
procedure TfrmPrincipal.btnInfoClick(Sender: TObject);
var
jsonRoot: TJSONObject;
tokenRequest: TRESTRequest;
tokenResponse: TRESTResponse;
tokenClient: TRESTClient;
tokenAutenticacao: TOAuth2Authenticator;
begin
tokenClient := TRESTClient.Create(nil);
tokenRequest := TRESTRequest.Create(nil);
tokenResponse := TRESTResponse.Create(nil);
tokenAutenticacao := TOAuth2Authenticator.Create(nil);
try
tokenRequest.Client := tokenClient;
tokenRequest.Response := tokenResponse;
tokenRequest.Method := TRESTRequestMethod.rmPUT;
tokenClient.Authenticator := tokenAutenticacao;
tokenAutenticacao.TokenType := TOAuth2TokenType.ttBEARER;
tokenAutenticacao.AccessToken := 'token_string';
tokenClient.BaseURL := 'http://host/url/method';
tokenRequest.Execute;
jsonRoot:= TJSONObject.ParseJSONValue(tokenResponse.JSONText) as TJSONObject;
Memo1.Lines.Add('cdPlayer …Run Code Online (Sandbox Code Playgroud)