STRFTIME
Formats the datetimeSynopsis
STRFTIME([<epoch>][,[<timezone>][,<format>]])Description
Formats the time specified by <epoch>, localized to <timezone>. The format comes directly from the underlying C function strftime(3). If <epoch> is not specified, defaults to the current time. <timezone> likewise defaults to the timezone on the host computer. A list of possible timezones may be obtained from the directory listing in /usr/share/zoneinfo. The default format is %c.This example sets the variable CallTime to the correct local time string in the format Unix utilities like `touch` want, i.e. YYYYMMDDhhmm:
exten => s,n,set(CallTime=${STRFTIME(${EPOCH},GMT+8,%C%y%m%d%H%M)})
Format String
This will vary from distribution to distribution, as their are different implementations of strftime. If these values do not work correctly on your system, please consult the man page for your implementation of strftime (you can do this by running `man 3 strftime` from your server's command line).The following values are based on an <epoch> value of 1185130650 (obtained via the ${EPOCH} variable) at -0400 or Eastern Daylight Time (EDT). The output of the Unix `date` command is:
[root@asterisk]# date
Sun Jul 22 14:57:30 EDT 2007
These format strings are from the CentOS 5.0 man page for strftime(3):
Format String | Description | Example |
---|---|---|
%a | The abbreviated weekday name according to the current locale. | Sun |
%A | The full weekday name according to the current locale. | Sunday |
%b | The abbreviated month name according to the current locale. | Jul |
%B | The full month name according to the current locale. | July |
%c | The preferred date and time representation for the current locale. | Sun Jul 22 14:57:30 2007 |
%C | The century number (year/100) as a 2-digit integer. | 20 |
%d | The day of the month as a decimal number (range 01 to 31). | 22 |
%D | Equivalent to %m/%d/%y. (Yecch — for Americans only. Americans should note that in other countries %d/%m/%y is rather common. This means that in international context this format is ambiguous and should not be used.) | 07/22/07 |
%e | Like %d, the day of the month as a decimal number, but a leading zero is replaced by a space. | 22 |
%F | Equivalent to %Y-%m-%d (the ISO 8601 date format). | 2007-07-22 |
%G | The ISO 8601 year with century as a decimal number. The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %y, except that if the ISO week number belongs to the previous or next year, that year is used instead. | 2007 |
%g | Like %G, but without century, i.e., with a 2-digit year (00-99). | 07 |
%h | Equivalent to %b. | Jul |
%H | The hour as a decimal number using a 24-hour clock (range 00 to 23). ... |