convert_date
This filter calls the [convert-date] tag to format
a date according to the specified format string.
The input date is expected to be in the "YYYY-MM-DD" format,
with an optional "HH:MM:SS" time specification.
The parameter is expected to be a date/time specification,
using the
POSIX strftime
tokens
listed here.
The default is "%d-%b-%Y %I:%M%p" if a time is provided,
otherwise it is "%d-%b-%Y".
Also see the strftime filter.
Example
- [filter convert_date]2007-01-02[/filter]
- [filter convert_date]2007-01-02 22:15[/filter]
- [filter convert_date.%Y-%m-%d.%H:%M:%S]2007-01-02 22:15[/filter]
- [filter convert_date."%A %d %B %Y at %I:%M %p"]2007-01-02 22:15[/filter]
|
Results in:
- 02-Jan-2007
- 02-Jan-2007 10:15PM
- 2007-01-02 22:15:00
- Tuesday 02 January 2007 at 10:15 PM
|
Source code
sub {
my $time = shift(@_);
return '' unless $time;
shift(@_);
my $fmt = shift(@_);
while(my $add = shift(@_)) {
$fmt .= " $add";
}
return $Tag->convert_date({ fmt => $fmt, body => $time});
}
|