was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

41 Visitors Online


 
... RFC1123 in ein TDateTime umwandeln?
Autor: w3seek
Homepage: http://www.w3seek.de
[ Tip ausdrucken ]  

Tip Bewertung (3):  
     


function RFC1123ToDateTime(Date: string): TDateTime;
var
  
day, month, year: Integer;
  strMonth: string;
  Hour, Minute, Second: Integer;
begin
  try
    
day      := StrToInt(Copy(Date, 6, 2));
    strMonth := Copy(Date, 9, 3);
    if strMonth = 'Jan' then month := 1 
    else if strMonth = 'Feb' then month := 2 
    else if strMonth = 'Mar' then month := 3 
    else if strMonth = 'Apr' then month := 4 
    else if strMonth = 'May' then month := 5 
    else if strMonth = 'Jun' then month := 6 
    else if strMonth = 'Jul' then month := 7 
    else if strMonth = 'Aug' then month := 8 
    else if strMonth = 'Sep' then month := 9 
    else if strMonth = 'Oct' then month := 10 
    else if strMonth = 'Nov' then month := 11 
    else if strMonth = 'Dec' then month := 12;
    year   := StrToInt(Copy(Date, 13, 4));
    hour   := StrToInt(Copy(Date, 18, 2));
    minute := StrToInt(Copy(Date, 21, 2));
    second := StrToInt(Copy(Date, 24, 2));
    Result := 0;
    Result := EncodeTime(hour, minute, second, 0);
    Result := Result + EncodeDate(year, month, day);
  except
    
Result := now;
  end;
end;


function DateTimeToRFC1123(aDate: TDateTime): string;
const
  
StrWeekDay: string = 'MonTueWedThuFriSatSun';
  StrMonth: string = 'JanFebMarAprMayJunJulAugSepOctNovDec';
var
  
Year, Month, Day: Word;
  Hour, Min, Sec, MSec: Word;
  DayOfWeek: Word;
begin
  
DecodeDate(aDate, Year, Month, Day);
  DecodeTime(aDate, Hour, Min, Sec, MSec);
  DayOfWeek := ((Trunc(aDate) - 2) mod 7);
  Result    := Copy(StrWeekDay, 1 + DayOfWeek * 3, 3) + ', ' +
    Format('%2.2d %s %4.4d %2.2d:%2.2d:%2.2d',
    [Day, Copy(StrMonth, 1 + 3 * (Month - 1), 3),
    Year, Hour, Min, Sec]);
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners