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