In Delphi is there a function to convert XML date and time to TDateTime

前端 未结 3 1991
别那么骄傲
别那么骄傲 2020-12-13 05:10

XML date and time are in the format

\'-\'? yyyy \'-\' mm \'-\' dd \'T\' hh \':\' mm \':\' ss (\'.\' s+)? (zzzzzz)?

were

•\'-\'? yy

3条回答
  •  無奈伤痛
    2020-12-13 05:27

    Delphi has a XSBuiltIns unit (since Delphi 6) that contains data types that can help you convert some XML data types:

    • TXSDate
    • TXSTime
    • TXSDateTime

    (there are more, like TXSDecimal, you get the idea)

    All of these contain at least these two methods:

    • NativeToXS
    • XSToNative

    You can use it like this:

    with TXSDateTime.Create() do
      try
        AsDateTime := ClientDataSetParam.AsDateTime; // convert from TDateTime
        Attribute.DateTimeValue := NativeToXS; // convert to WideString
      finally
        Free;
      end;
    
    with TXSDateTime.Create() do
      try
        XSToNative(XmlAttribute.DateTimeValue); // convert from WideString
        CurrentField.AsDateTime := AsDateTime; // convert to TDateTime
      finally
        Free;
      end;
    

    That should get you going.

    --jeroen

提交回复
热议问题