Op 2018-12-13 om 21:07 schreef luciano de souza:
Hello all, I'd like to convert this date "2017-01-11T17:47:22.2912317-02:00" to TDatetime.
A quick attempt with some standard functions, note that it only parses till millisecond precision, the rest (317) is ignored.
uses dateutils,sysutils,strutils; const teststring = '2017-01-11T17:47:22.2912317-02:00'; var dt : TDatetime; myYear, myMonth, myDay : Word; myHour, myMin, mySec, myMilli : Word; s3:string; i : integer; begin i:=rpos('-',teststring); s3:=copy(teststring,1,i-1); dt:=scandatetime('yyyy-mm-dd?hh:nn:ss.zzz????',s3); writeln(dt); decodedatetime(dt,myYear, myMonth, myDay, myHour, myMin, mySec, myMilli); writeln('myHour = '+IntToStr(myHour)); writeln('myMin = '+IntToStr(myMin)); writeln('mySec = '+IntToStr(mySec)); writeln('myMilli = '+IntToStr(myMilli)); writeln('myDay = '+IntToStr(myDay)); writeln('myMonth = '+IntToStr(myMonth)); writeln('myYear = '+IntToStr(myYear)); s3:=copy(teststring,i+1,length(teststring)-i); // parse timezone info dt:=scandatetime('hh:nn',s3); decodetime(dt, myHour, myMin, mySec, myMilli); writeln('tzmyHour = '+IntToStr(myHour)); writeln('tzmyMin = '+IntToStr(myMin)); end. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal