views:

1390

answers:

3

eg. var tm : string; dt : tdatetime;

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

I know I can parse it manually but I wonder if there is built-in function or win32 api function to do this ?

Any help would be appreciated.

+2  A: 

https://forums.codegear.com/thread.jspa?threadID=16074

Brave Cobra
I like the idea of using the XSBuiltIns functions - don't reinvent the wheel.
Gerry
There is bug in XMLTimeToDateTime http://qc.embarcadero.com/wc/qcmain.aspx?d=9547. After I apply fix, it's working now.Thanks!
Irwan
A: 

This looks like an internet protocol related activity, so you should have no problems in using the Win32 API for this. However note, that Windows does not correctly support conversion to/from UTC for historical dates that are more than approximately 20 years old - Windows simply doesn't have enough details in its time zone settings for that.

Lars D
A: 

I don't know why there are so many people shooting their mouth off when they don't know what they are talking about? I have to do this menial work; Is it a RAD tool? I sometimes find Delphi has a real superb architecture, though.

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 EConvertError do
      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://coding.derkeiler.com/Archive/Delphi/comp.lang.pascal.delphi.misc/2006-08/msg00190.html

delphi_hangover