Date::TimeFormat - Timestamp formating functions
use Date::TimeFormat; print format_time(), "\n";
This module provides functions to format unix timestamp (number of seconds since the epoch, that is 1970-01-01 00:00:00 GMT) into string.
Please, note this module was created with 5 purposes in mind: work with integer timestamp (and not with array of 9 integers like POSIX::strftime), have sane defaults (i.e. 2006-07-31 and not confusing 03/02/01 for the date part ``%x''), support new specifier ``%o'' (time age), be light and produce locale-independent results.
If you need more robust time-date functions, take a look at other modules.
By default, function format_time is exported. If desired, you may
specify any other function name(s) to be exported instead, and work
just like format_time:
use Date::TimeFormat qw(strftime);
use Date::TimeFormat qw(time2str);
Additionally, you may also export function time_age($time), that returns
the same as format_time("%o", $time), just without trailing `` ago'':
use Date::TimeFormat qw(format_time time_age);
my $local_time_str = format_time();
print format_time("Universal Time: %c GMT", time, 0);
Specifiers contradicting to POSIX::strftime:
FORMAT POSIX Date::TimeFormat
%c %a %b %e %T %Y %a %d %b %Y %T
%D mm/dd/yy dd/mm/yy
%x mm/dd/yy yyyy-mm-dd
%U real week num 0
%W real week num 0
%z real time zone +0099
%Z real time zone XXT
%o INVALID 12 days ago
* optional time format string; default is '%x %X'
* optional timestamp (number of seconds since the Epoch)
* optional timezone offset in minutes or +NNNN/-NNNN format
(0 or '+0000' or '-0000' all mean 'GMT'),
by default the current timezone (i.e. local time) is assumed
%% a literal % %a day of the week, abbreviated %A day of the week %b month, abbreviated %B month %c DD/MM/YY HH:MM:SS %C ctime format: Sat 12 Nov 2006 15:42:06 %d numeric day of the month, with leading zeros (eg 01..31) %e numeric day of the month, with leading space (eg 1..31) %D DD/MM/YY %h month, abbreviated %H hour, 24 hour clock, leading 0's %I hour, 12 hour clock, leading 0's %j day of the year %k hour %l hour, 12 hour clock %m month number, starting with 01 %M minute, leading 0's %n newline char %o age string (eg "7 weeks ago") %p AM or PM %P am or pm %r time format: 08:03:45 PM %R time format: 21:05 %s seconds since the Epoch %S seconds, leading 0's %t tab char %T time format: 21:05:57 %U week number, Sunday as first day of week %w day of the week, numerically, Sunday == 0 %W week number, Monday as first day of week %x date format: 2000-11-19 %X time format: 15:03:09 %y year (2 digits) %Y year (4 digits) %Z timezone in ascii, eg: IST %z timezone in format -/+0200
See date(1), the Date::Format manpage and the POSIX manpage::stftime.