RFC 1123 Time Format: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: RFC 1123 Time Format
| Old | New | Line | |
|---|---|---|---|
| 1 | + | [[Function]] RFC1123TimeFormat(aDateTime:[[TDateTime]]; isLocalTime:boolean):string; creates and displays the time in the RFC 1123 International format: | |
| 2 | + | ||
| 3 | + | ` DAY, DD MON YYYY hh:mm:ss GMT` | |
| 4 | + | ||
| 5 | + | e.g: | |
| 6 | + | ||
| 7 | + | ` Sun, 21 Oct 2018 12:16:24 GMT` | |
| 8 | + | ||
| 9 | + | 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. | |
| 10 | + | ||
| 11 | + | 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) | |
| 12 | + | ||
| 13 | + | The time is Coordinated Universal Time (UTC), though the indication can optionally be Greenwich Mean Time (GMT) | |
| 14 | + | ||
| 15 | + | ## program RFC1123_TimeFormat | |
| 16 | + | ||
| 17 | + | ``` pascal | |
| 18 | + | program RFC1123_TimeFormat; | |
| 19 | + | ||
| 20 | + | uses | |
| 21 | + | SysUtils, DateUtils; | |
| 22 | + | ||
| 23 | + | function RFC1123TimeFormat(aDateTime:TDateTime; isLocalTime:boolean):string; | |
| 24 | + | const | |
| 25 | + | ShortDayNamesEnglish :array[1..7] of string = | |
| 26 | + | ('Sun', 'Mon','Tue', 'Wed', 'Thu', 'Fri', 'Sat'); | |
| 27 | + | ShortMonthNamesEnglish :array[1..12] of string = ('Jan', 'Feb','Mar', 'Apr', | |
| 28 | + | 'May','Jun','Jul','Aug', 'Sep','Oct','Nov','Dec'); | |
| 29 | + | var | |
| 30 | + | day,month : string; | |
| 31 | + | someDateTime:TDateTime; | |
| 32 | + | begin | |
| 33 | + | if isLocalTime then someDateTime := LocalTimeToUniversal(aDateTime) | |
| 34 | + | else someDateTime := aDateTime; | |
| 35 | + | day := ShortDayNamesEnglish[DayOfWeek(someDateTime)]; | |
| 36 | + | month := ShortMonthNamesEnglish[MonthOf(someDateTime)] ; | |
| 37 | + | result := day+', '+FormatDateTime('dd', someDateTime)+' '+ | |
| 38 | + | month+' '+FormatDateTime('yyyy hh:nn:ss', someDateTime)+' GMT'; | |
| 39 | + | end; | |
| 40 | + | ||
| 41 | + | var | |
| 42 | + | someDate: TDateTime; | |
| 43 | + | begin | |
| 44 | + | someDate := EncodeDate(2018, 10, 23); | |
| 45 | + | WriteLn(RFC1123TimeFormat(now,true)); | |
| 46 | + | WriteLn(RFC1123TimeFormat(someDate,false)); | |
| 47 | + | ReadLn; | |
| 48 | + | end. | |
| 49 | + | ``` | |
| 50 | + | ||
| 51 | + | [[Unit]] DateUtils function LocalTimeToUniversal convert local time to UTC time Declaration | |
| 52 | + | ||
| 53 | + | ``` pascal | |
| 54 | + | function LocalTimeToUniversal( LT: TDateTime ):TDateTime; | |
| 55 | + | ``` | |
| 56 | + | ||
| 57 | + | Unit SysUtils function FormatDateTime provides rich formatting of a TDateTime value into a string. Formatting is defined by the Formatting string. | |
| 58 | + | ||
| 59 | + | ``` pascal | |
| 60 | + | function FormatDateTime ( const Formatting : string; DateTime : TDateTime ) : string; | |
| 61 | + | ``` | |
| 62 | + | ||
| 63 | + | Unit SysUtils function EncodeDate build a TDateTime value from year, month and day values | |
| 64 | + | ||
| 65 | + | ``` pascal | |
| 66 | + | function EncodeDate(Year, Month, Day :word): TDateTime; | |
| 67 | + | ``` | |
| 68 | + | ||
| 69 | + | ## See also | |
| 70 | + | ||
| 71 | + | - [[TDateTime]] | |
| 72 | + | - Date and time format [[ISO 8601]] | |
| 73 | + | ||
| 74 | + | --- | |
| 75 | + | *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](/wiki-contact).* |
