Asterisk func strftime

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
%aThe abbreviated weekday name according to the current locale.Sun
%AThe full weekday name according to the current locale.Sunday
%bThe abbreviated month name according to the current locale.Jul
%BThe full month name according to the current locale.July
%cThe preferred date and time representation for the current locale.Sun Jul 22 14:57:30 2007
%CThe century number (year/100) as a 2-digit integer.20
%dThe day of the month as a decimal number (range 01 to 31).22
%DEquivalent 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
%eLike %d, the day of the month as a decimal number, but a leading zero is replaced by a space.22
%FEquivalent to %Y-%m-%d (the ISO 8601 date format).2007-07-22
%GThe 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
%gLike %G, but without century, i.e., with a 2-digit year (00-99).07
%hEquivalent to %b.Jul
%HThe hour as a decimal number using a 24-hour clock (range 00 to 23).14
%IThe hour as a decimal number using a 12-hour clock (range 01 to 12).02
%jThe day of the year as a decimal number (range 001 to 366).203
%kThe hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank. (See also %H.)14
%lThe hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank. (See also %I.)2
%mThe month as a decimal number (range 01 to 12).07
%MThe minute as a decimal number (range 00 to 59).57
%nA newline character.
%pEither ‘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
%PLike %p but in lowercase: ‘am’ or ‘pm’ or a corresponding string for the current locale.pm
%rThe time in a.m. or p.m. notation. In the POSIX locale this is equivalent to ‘%I:%M:%S %p’.02:57:30 PM
%RThe time in 24-hour notation (%H:%M). For a version including the seconds, see %T below.14:57
%sThe number of seconds since the Epoch, i.e., since 1970-01-01 00:00:00 UTC.1185130650
%SThe second as a decimal number (range 00 to 60). (The range is up to 60 to allow for occasional leap seconds.)30
%tA tab character.
%TThe time in 24-hour notation (%H:%M:%S).14:57:30
%uThe day of the week as a decimal, range 1 to 7, Monday being 1. See also %w.7
%UThe 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
%VThe 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
%wThe day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u.0
%WThe 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
%xThe preferred date representation for the current locale without the time.07/22/07
%XThe preferred time representation for the current locale without the date.14:57:30
%yThe year as a decimal number without a century (range 00 to 99).07
%YThe year as a decimal number including the century.2007
%zThe time-zone as hour offset from GMT. Required to emit RFC 822-conformant dates (using "%a, %d %b %Y %H:%M:%S %z").-0400
%ZThe time zone or name or abbreviation.EDT
%%A literal ‘%’ character.%


See also

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
%aThe abbreviated weekday name according to the current locale.Sun
%AThe full weekday name according to the current locale.Sunday
%bThe abbreviated month name according to the current locale.Jul
%BThe full month name according to the current locale.July
%cThe preferred date and time representation for the current locale.Sun Jul 22 14:57:30 2007
%CThe century number (year/100) as a 2-digit integer.20
%dThe day of the month as a decimal number (range 01 to 31).22
%DEquivalent 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
%eLike %d, the day of the month as a decimal number, but a leading zero is replaced by a space.22
%FEquivalent to %Y-%m-%d (the ISO 8601 date format).2007-07-22
%GThe 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
%gLike %G, but without century, i.e., with a 2-digit year (00-99).07
%hEquivalent to %b.Jul
%HThe hour as a decimal number using a 24-hour clock (range 00 to 23).14
%IThe hour as a decimal number using a 12-hour clock (range 01 to 12).02
%jThe day of the year as a decimal number (range 001 to 366).203
%kThe hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank. (See also %H.)14
%lThe hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank. (See also %I.)2
%mThe month as a decimal number (range 01 to 12).07
%MThe minute as a decimal number (range 00 to 59).57
%nA newline character.
%pEither ‘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
%PLike %p but in lowercase: ‘am’ or ‘pm’ or a corresponding string for the current locale.pm
%rThe time in a.m. or p.m. notation. In the POSIX locale this is equivalent to ‘%I:%M:%S %p’.02:57:30 PM
%RThe time in 24-hour notation (%H:%M). For a version including the seconds, see %T below.14:57
%sThe number of seconds since the Epoch, i.e., since 1970-01-01 00:00:00 UTC.1185130650
%SThe second as a decimal number (range 00 to 60). (The range is up to 60 to allow for occasional leap seconds.)30
%tA tab character.
%TThe time in 24-hour notation (%H:%M:%S).14:57:30
%uThe day of the week as a decimal, range 1 to 7, Monday being 1. See also %w.7
%UThe 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
%VThe 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
%wThe day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u.0
%WThe 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
%xThe preferred date representation for the current locale without the time.07/22/07
%XThe preferred time representation for the current locale without the date.14:57:30
%yThe year as a decimal number without a century (range 00 to 99).07
%YThe year as a decimal number including the century.2007
%zThe time-zone as hour offset from GMT. Required to emit RFC 822-conformant dates (using "%a, %d %b %Y %H:%M:%S %z").-0400
%ZThe time zone or name or abbreviation.EDT
%%A literal ‘%’ character.%


See also

Created by: Corydon76, Last modification: Wed 29 of May, 2013 (23:46 UTC) by JustRumours
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+