Question

Is there any simple option to convert a U.S. TDateTime value Apr 17, 2014 8:35:38 PM PDT to a European format looking like 2014-04-17 20:35:38?

EDIT:

I have a string containing raw date/time in U.S. format:

var s, new_s: string;
begin
  s := 'Apr 17, 2014 8:35:38 PM PDT';

I want to somehow read/parse this string to a variable of TDateTime type -or- just convert it to another string of the desired format:

  new_s := MyConvertDateTimeSring(s);
  // now new_s must be '2014-04-17 20:35:38';
end; 

(Delphi XE4)

Was it helpful?

Solution

If you remove the TimeZone PDT from the string then you can use VarToDateTime to convert the string into a TDateTime value

var
  LDateTimeStr : string;
  LDateTime : TDateTime;
begin
  LDateTimeStr := 'Apr 17, 2014 8:35:38 PM PDT';
  LDateTime := VarToDateTime( Copy( LDateTimeStr, 1, 23 ) );
  WriteLn( FormatDateTime( 'yyyy-mm-dd hh:nn:ss', LDateTime ) );
end;

The result will be

2014-04-17 20:35:38

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top