Author: Christian Cristofori
I was trying to convert a DateTime value to a RFC822 style date, so I asked to
Paolo, a friend of mine, if he did know how it works. He found that on the Net.
It's not perfect... someone as a better one?
Answer:
1
2 function DateTimeToRFC822(DTTime: TDateTime): string;
3 var
4 IdX: Integer;
5 SaveShortDayNames: array[1..7] of string;
6 SaveShortMonthNames: array[1..12] of string;
7 const
8 MyShortDayNames: array[1..7] of string = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu',
9 'Fri',
10 'Sat');
11 MyShortMonthNames: array[1..12] of string = ('Jan', 'Feb', 'Mar', 'Apr', 'May',
12 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
13 begin
14 if (ShortDayNames[1] = MyShortDayNames[1]) then
15 Result := FormatDateTime('ddd, d mmm yyyy hh:mm:ss', DTTime)
16 else
17 begin
18 for IdX := Low(ShortDayNames) to High(ShortDayNames) do
19 begin
20 SaveShortDayNames[IdX] := ShortDayNames[IdX];
21 ShortDayNames[IdX] := MyShortDayNames[IdX];
22 end;
23 for IdX := Low(ShortMonthNames) to High(ShortMonthNames) do
24 begin
25 SaveShortMonthNames[IdX] := ShortMonthNames[IdX];
26 ShortMonthNames[IdX] := MyShortMonthNames[IdX];
27 end;
28 Result := FormatDateTime('ddd, d mmm yyyy hh:mm:ss', DTTime);
29 for IdX := Low(ShortDayNames) to High(ShortDayNames) do
30 ShortDayNames[IdX] := SaveShortDayNames[IdX];
31 for IdX := Low(ShortMonthNames) to High(ShortMonthNames) do
32 ShortMonthNames[IdX] := SaveShortMonthNames[IdX];
33 end;
34 end;
|