MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
| 2 | string strftime() |
| 3 | string strftime(string fmt) |
| 4 | string strftime(int clock) |
| 5 | string strftime(string fmt, int clock) |
| 6 | string strftime(string fmt, int clock, int localized) |
| 7 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 8 | DESCRIPTION |
| 9 | The function strftime() formats the given time in <clock> as a formatted |
| 10 | string, similar to ctime(). Unlike ctime(), strftime() accepts a format |
| 11 | string with placeholders for the different elements. The format string |
| 12 | consists of zero or more conversion specifiers (see below) and ordinary |
| 13 | characters. Ordinary charaecters are just copied to the result. A |
| 14 | conversion specifier starts with a percent sign ('%'). If no format |
| 15 | string is given, a default of "%c" will be used. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 17 | The argument <clock> is the number of seconds since the epoch (00:00:00 |
| 18 | UTC, January 1, 1970), as returned by time/mktime(). If <clock> is not |
| 19 | given, the current result of time() will be used. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 20 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 21 | The argument <localized> specifies, whether the result will be in english |
| 22 | (the classic "C" locale) or in the language configured on the host |
| 23 | computer (e.g. german). The language has to be configured with the |
| 24 | environment variables LC_TIME or LC_ALL (please ask your admins). If |
| 25 | <localized> is not given, the default is 1. |
| 26 | 0: use classic "C" locale (english) |
| 27 | 1: use current locale on the host computer (national representation). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 28 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 29 | REMARKS: |
| 30 | The resulting string is at most 511 character long. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 31 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 32 | CONVERSION SPECIFIERS: |
| 33 | This function accepts all conversion specifiers, which the function |
| 34 | strftime() from the C library accepts. Currently these are: |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 35 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 36 | %A is replaced by national representation of the full weekday name. |
| 37 | %a is replaced by national representation of the abbreviated weekday |
| 38 | name. |
| 39 | %B is replaced by national representation of the full month name. |
| 40 | %b is replaced by national representation of the abbreviated month name. |
| 41 | %C is replaced by (year / 100) as decimal number; single digits are |
| 42 | preceded by a zero. |
| 43 | %c is replaced by national representation of time and date. |
| 44 | %D is equivalent to ``%m/%d/%y''. |
| 45 | %d is replaced by the day of the month as a decimal number (01-31). |
| 46 | %E* %O* |
| 47 | POSIX locale extensions. The sequences %Ec %EC %Ex %EX %Ey %EY %Od |
| 48 | %Oe %OH %OI %Om %OM %OS %Ou %OU %OV %Ow %OW %Oy are supposed to |
| 49 | provide alternate representations. |
| 50 | Additionally %OB implemented to represent alternative |
| 51 | months names (used standalone, without day mentioned). |
| 52 | %e is replaced by the day of month as a decimal number (1-31); single |
| 53 | digits are preceded by a blank. |
| 54 | %F is equivalent to ``%Y-%m-%d''. |
| 55 | %G is replaced by a year as a decimal number with century. This year |
| 56 | is the one that contains the greater part of the week (Monday as |
| 57 | the first day of the week). |
| 58 | %g is replaced by the same year as in ``%G'', but as a decimal number |
| 59 | without century (00-99). |
| 60 | %H is replaced by the hour (24-hour clock) as a decimal number (00-23). |
| 61 | %h the same as %b. |
| 62 | %I is replaced by the hour (12-hour clock) as a decimal number (01-12). |
| 63 | %j is replaced by the day of the year as a decimal number (001-366). |
| 64 | %k is replaced by the hour (24-hour clock) as a decimal number (0-23); |
| 65 | single digits are preceded by a blank. |
| 66 | %l is replaced by the hour (12-hour clock) as a decimal number (1-12); |
| 67 | single digits are preceded by a blank. |
| 68 | %M is replaced by the minute as a decimal number (00-59). |
| 69 | %m is replaced by the month as a decimal number (01-12). |
| 70 | %n is replaced by a newline. |
| 71 | %O* the same as %E*. |
| 72 | %p is replaced by national representation of either "ante meridiem" or |
| 73 | "post meridiem" as appropriate. |
| 74 | %R is equivalent to ``%H:%M''. |
| 75 | %r is equivalent to ``%I:%M:%S %p''. |
| 76 | %S is replaced by the second as a decimal number (00-60). |
| 77 | %s is replaced by the number of seconds since the Epoch, UTC (see |
| 78 | mktime(3)). |
| 79 | %T is equivalent to ``%H:%M:%S''. |
| 80 | %t is replaced by a tab. |
| 81 | %U is replaced by the week number of the year (Sunday as the |
| 82 | first day of the week) as a decimal number (00-53). |
| 83 | %u is replaced by the weekday (Monday as the first day of |
| 84 | the week) as a decimal number (1-7). |
| 85 | %V is replaced by the week number of the year (Monday as the |
| 86 | first day of the week) as a decimal number (01-53). If the week |
| 87 | containing January 1st has four or more days in the new year, |
| 88 | then it is week 1; otherwise it is the last week of the previous |
| 89 | year, and the next week is week 1. |
| 90 | %v is equivalent to ``%e-%b-%Y''. |
| 91 | %W is replaced by the week number of the year (Monday as the |
| 92 | first day of the week) as a decimal number (00-53). |
| 93 | %w is replaced by the weekday (Sunday as the first day of the week) |
| 94 | as a decimal number (0-6). |
| 95 | %X is replaced by national representation of the time. |
| 96 | %x is replaced by national representation of the date. |
| 97 | %Y is replaced by the year with century as a decimal number. |
| 98 | %y is replaced by the year without century as a decimal number (00-99). |
| 99 | %Z is replaced by the time zone name. |
| 100 | %z is replaced by the time zone offset from UTC; a leading plus sign |
| 101 | stands for east of UTC, a minus sign for west of UTC, hours and |
| 102 | minutes follow with two digits each and no delimiter between |
| 103 | them (common form for RFC 822 date headers). |
| 104 | %+ is replaced by national representation of the date and time |
| 105 | (the format is similar to that produced by date(1)). |
| 106 | %% is replaced by `%'. |
| 107 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 108 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 109 | BUGS |
| 110 | There is no conversion specification for the phase of the moon. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 111 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 112 | EXAMPLES |
| 113 | write(strftime("Today is %A, %d. %B %Y.\n")) |
| 114 | results in "Today is Monday, 24. September 2007.\n" |
| 115 | |
| 116 | HISTORY |
| 117 | Introduced in LDMud 3.3.718. |
| 118 | |
| 119 | SEE ALSO |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 120 | ctime(E), gmtime(E), localtime(E), mktime(E), time(E), utime(E) |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 121 | |