2010. július 11., vasárnap
Convert from DateTime to RFC822 date
Problem/Question/Abstract:
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:
function DateTimeToRFC822(DTTime: TDateTime): string;
var
IdX: Integer;
SaveShortDayNames: array[1..7] of string;
SaveShortMonthNames: array[1..12] of string;
const
MyShortDayNames: array[1..7] of string = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri',
'Sat');
MyShortMonthNames: array[1..12] of string = ('Jan', 'Feb', 'Mar', 'Apr', 'May',
'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
begin
if (ShortDayNames[1] = MyShortDayNames[1]) then
Result := FormatDateTime('ddd, d mmm yyyy hh:mm:ss', DTTime)
else
begin
for IdX := Low(ShortDayNames) to High(ShortDayNames) do
begin
SaveShortDayNames[IdX] := ShortDayNames[IdX];
ShortDayNames[IdX] := MyShortDayNames[IdX];
end;
for IdX := Low(ShortMonthNames) to High(ShortMonthNames) do
begin
SaveShortMonthNames[IdX] := ShortMonthNames[IdX];
ShortMonthNames[IdX] := MyShortMonthNames[IdX];
end;
Result := FormatDateTime('ddd, d mmm yyyy hh:mm:ss', DTTime);
for IdX := Low(ShortDayNames) to High(ShortDayNames) do
ShortDayNames[IdX] := SaveShortDayNames[IdX];
for IdX := Low(ShortMonthNames) to High(ShortMonthNames) do
ShortMonthNames[IdX] := SaveShortMonthNames[IdX];
end;
end;
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése