STRFTIME
Formats the datetime
Synopsis
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). | 14 |
%I | The hour as a decimal number using a 12-hour clock (range 01 to 12). | 02 |
%j | The day of the year as a decimal number (range 001 to 366). | 203 |
%k | The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank. (See also %H.) | 14 |
%l | The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank. (See also %I.) | 2 |
%m | The month as a decimal number (range 01 to 12). | 07 |
%M | The minute as a decimal number (range 00 to 59). | 57 |
%n | A newline character. | |
%p | Either ‘AM’ or ‘PM’ according to the given time value, or the corresponding strings for the current locale. Noon is treated as ‘pm’ and midnight as ‘am’. | PM |
%P | Like %p but in lowercase: ‘am’ or ‘pm’ or a corresponding string for the current locale. | pm |
%r | The time in a.m. or p.m. notation. In the POSIX locale this is equivalent to ‘%I:%M:%S %p’. | 02:57:30 PM |
%R | The time in 24-hour notation (%H:%M). For a version including the seconds, see %T below. | 14:57 |
%s | The number of seconds since the Epoch, i.e., since 1970-01-01 00:00:00 UTC. | 1185130650 |
%S | The second as a decimal number (range 00 to 60). (The range is up to 60 to allow for occasional leap seconds.) | 30 |
%t | A tab character. | |
%T | The time in 24-hour notation (%H:%M:%S). | 14:57:30 |
%u | The day of the week as a decimal, range 1 to 7, Monday being 1. See also %w. | 7 |
%U | The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. See also %V and %W. | 29 |
%V | The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. See also %U and %W. | 29 |
%w | The day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u. | 0 |
%W | The week number of the current year as a decimal number, range 00 to 53, starting with the first Monday as the first day of week 01. | 29 |
%x | The preferred date representation for the current locale without the time. | 07/22/07 |
%X | The preferred time representation for the current locale without the date. | 14:57:30 |
%y | The year as a decimal number without a century (range 00 to 99). | 07 |
%Y | The year as a decimal number including the century. | 2007 |
%z | The time-zone as hour offset from GMT. Required to emit RFC 822-conformant dates (using “%a, %d %b %Y %H:%M:%S %z”). | -0400 |
%Z | The time zone or name or abbreviation. | EDT |
%% | A literal ‘%’ character. | % |
See also
- Asterisk func strptime
- Asterisk func timeout: Set one of three type of timeouts for a call
- Asterisk cmd SayUnixTime: Say date and time
- Asterisk functions