Difference between revisions of "RFC 1123 Time Format"

From Lazarus wiki
Jump to navigationJump to search
(remove redundant level-1 heading)
 
Line 1: Line 1:
 
{{RFC 1123 Time Format}}
 
{{RFC 1123 Time Format}}
 
= RFC 1123 Time Format =
 
  
 
[[Function]] RFC1123TimeFormat(aDateTime:[[TDateTime]]; isLocalTime:boolean):string;
 
[[Function]] RFC1123TimeFormat(aDateTime:[[TDateTime]]; isLocalTime:boolean):string;
Line 9: Line 7:
 
e.g:
 
e.g:
 
   Sun, 21 Oct 2018 12:16:24 GMT
 
   Sun, 21 Oct 2018 12:16:24 GMT
 
  
 
Day in the form of DAY, three letter abbreviation followed by a [[Comma|comma]].
 
Day in the form of DAY, three letter abbreviation followed by a [[Comma|comma]].
 
Date in the form DD-MON-YYYY (day, month, and year), where Month in the form three letter abbreviation.
 
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,
+
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)
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)
 
The time is Coordinated Universal Time (UTC), though the indication can optionally be Greenwich Mean Time (GMT)
  
 
== program RFC1123_TimeFormat ==
 
== program RFC1123_TimeFormat ==
 
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
 
program RFC1123_TimeFormat;
 
program RFC1123_TimeFormat;
  
Line 56: Line 49:
 
   ReadLn;
 
   ReadLn;
 
end.
 
end.
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
[[Unit]] DateUtils function LocalTimeToUniversal convert local time to UTC time
+
[[Unit]] DateUtils function LocalTimeToUniversal convert local time to UTC time Declaration
Declaration
 
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
   function LocalTimeToUniversal( LT: TDateTime ):TDateTime;
 
   function LocalTimeToUniversal( LT: TDateTime ):TDateTime;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Unit SysUtils function FormatDateTime provides rich formatting of
+
Unit SysUtils function FormatDateTime provides rich formatting of a TDateTime value into a string.
a TDateTime value into a string. Formatting is defined by the Formatting string.
+
Formatting is defined by the Formatting string.
  
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">

Latest revision as of 15:12, 7 September 2019

English (en) suomi (fi)

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

 DAY, DD MON YYYY hh:mm:ss GMT

e.g:

 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

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

  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.

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

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

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

See also