Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

RFC 1123 Time Format

English ยท Suomi

Function RFC1123TimeFormat(aDateTime:TDateTime; isLocalTime:boolean):string; creates and displays the time in the RFC 1123 International format:

text
 DAY, DD MON YYYY hh:mm:ss GMT

e.g:

text
 Sun, 21 Oct 2018 12:16:24 GMT

Day in the form of DAY, three letter abbreviation followed by a comma. Date in the form DD-MON-YYYY (day, month, and year), where Month in the form three letter abbreviation.

The date and time are displayed on the same line, date first followed by the time, and the time is in this format, with a space between the date's year and the hours, Time in the form hh:mm:ss (hours, minutes, and seconds)

The time is Coordinated Universal Time (UTC), though the indication can optionally be Greenwich Mean Time (GMT)

program RFC1123_TimeFormat

pascal
program RFC1123_TimeFormat;

uses
  SysUtils, DateUtils;

function RFC1123TimeFormat(aDateTime:TDateTime; isLocalTime:boolean):string;
const
  ShortDayNamesEnglish :array[1..7] of string =
    ('Sun', 'Mon','Tue', 'Wed', 'Thu', 'Fri', 'Sat');
  ShortMonthNamesEnglish :array[1..12] of string = ('Jan', 'Feb','Mar', 'Apr',
     'May','Jun','Jul','Aug', 'Sep','Oct','Nov','Dec');
var
   day,month : string;
   someDateTime:TDateTime;
begin
  if isLocalTime then someDateTime := LocalTimeToUniversal(aDateTime)
    else  someDateTime := aDateTime;
  day := ShortDayNamesEnglish[DayOfWeek(someDateTime)];
  month := ShortMonthNamesEnglish[MonthOf(someDateTime)] ;
  result := day+', '+FormatDateTime('dd', someDateTime)+' '+
    month+' '+FormatDateTime('yyyy hh:nn:ss', someDateTime)+' GMT';
end;

var
  someDate: TDateTime;
begin
  someDate := EncodeDate(2018, 10, 23);
  WriteLn(RFC1123TimeFormat(now,true));
  WriteLn(RFC1123TimeFormat(someDate,false));
  ReadLn;
end.

Unit DateUtils function LocalTimeToUniversal convert local time to UTC time Declaration

pascal
  function LocalTimeToUniversal( LT: TDateTime ):TDateTime;

Unit SysUtils function FormatDateTime provides rich formatting of a TDateTime value into a string. Formatting is defined by the Formatting string.

pascal
  function FormatDateTime ( const Formatting : string; DateTime : TDateTime ) : string;

Unit SysUtils function EncodeDate build a TDateTime value from year, month and day values

pascal
  function EncodeDate(Year, Month, Day :word): TDateTime;

See also


From the Free Pascal wiki, page "RFC 1123 Time Format", as it stood on 2019-09-07 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .