• Convert UTC string to TDatetime in Delphi


    eg. var tm : string; dt : tdatetime;

    tm := '2009-08-21T09:11:21Z'; dt := ?

    procedure setISOtoDateTime(strDT:string); 
    var 
     
    // Delphi settings save vars 
     
    ShortDF,ShortTF:string; 
      TS
    , DS :char; 
     
    // conversion vars 
      dd
    , tt, ddtt:TDateTime; 
    begin 
     
    // example datetime test string in ISO format 
      strDT
    :='2009-07-06T01:53:23Z'; 
     
     
    // save Delphi settings 
      DS
    :=DateSeparator; 
      TS
    :=TimeSeparator; 
     
    ShortDF:=ShortDateFormat; 
     
    ShortTF:=ShortTimeFormat; 
     
     
    // set Delphi settings for string to date/time 
     
    DateSeparator:='-'; 
     
    ShortDateFormat:='yyyy-mm-dd'; 
     
    TimeSeparator:=':'; 
     
    ShortTimeFormat:='hh:mm:ss'; 
     
     
    // convert test string to datetime 
     
    try 
     
        dd
    :=StrToDate(Copy(strDT,1,Pos('T',strDT)-1)); 
        tt
    :=StrToTime(Copy(strDT,Pos('T',strDT)+1,8)); 
        ddtt
    := trunc(dd)+ frac(tt); 
     
     
    except 
        on
    EConvertErrordo 
         
    ShowMessage('Error in converting : '+ strDT); 
     
    end; 
     
     
    // restore Delphi settings 
     
    DateSeparator:= DS; 
     
    ShortDateFormat:=ShortDF; 
     
    TimeSeparator:= TS; 
     
    ShortTimeFormat:=ShortTF; 
     
     
    // display test string 
     
    ShowMessage(FormatDateTime('mm/dd/yyyy hh:mm:ss', ddtt)); 
    end;

    http://qc.embarcadero.com/wc/qcmain.aspx?d=9547

  • 相关阅读:
    day11_获取前一条用例的结果(用参数化实现)
    day11_获取前一条用例的结果
    codeforce 1433F
    codeforces 1428 D. Bouncing Boomerangs (贪心)
    codeforces 761C
    codeforces 839C
    codeforces 859C
    codeforces 858C Did you mean... (贪心)
    codeforces 855B
    st表
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/2714599.html
Copyright © 2020-2023  润新知