POSIX::1003::Time - POSIX handling time
POSIX::1003::Time is a POSIX::1003
use POSIX::1003::Time; tzset(); # set-up local timezone from $ENV{TZ} ($std, $dst) = tzname; # timezone abbreviations $str = ctime($timestamp); # is equivalent to: $str = asctime(localtime($timestamp)) $str = strftime("%A, %B %d, %Y", 0, 0, 0, 12, 11, 95, 2); # $str contains "Tuesday, December 12, 1995" $timestamp = mktime(0, 30, 10, 12, 11, 95); print "Date = ", ctime($timestamp); print scalar localtime; my $year = (localtime)[5] + 1900; $timespan = difftime($end, $begin);
Warning: the functions asctime(), mktime(), and strftime() share a weird complex encoding with localtime() and gmtime(): the month (mon), weekday (wday), and yearday (yday) begin at zero. I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The year (year) is given in years since 1900. I.e., the year 1995 is 95; the year 2001 is 101.
mon
wday
yday
year
The asctime function uses strftime with a fixed format, to produce timestamps with a trailing new-line. Example:
asctime
strftime
"Sun Sep 16 01:03:52 1973\n"
The parameter order is the same as for strftime() without the $fmt:
$fmt
my $str = asctime($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
The amount of spent processor time in microseconds.
# equivalent my $str = ctime $timestamp; my $str = asctime localtime $timestamp;
Difference between two TIMESTAMPs, which are floats.
$timespan = difftime($end, $begin);
Simply "gmtime" in perlfunc
Simply "localtime" in perlfunc
Convert date/time info to a calendar time. Returns "undef" on failure.
my $t = mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1) # Calendar time for December 12, 1995, at 10:30 am $timestamp = mktime(0, 30, 10, 12, 11, 95); print "Date = ", ctime($time_t);
The formatting of strftime is extremely flexible but the parameters are quite tricky. Read carefully!
my $str = strftime($fmt, $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
If you want your code to be portable, your format (FMT) argument should use only the conversion specifiers defined by the ANSI C standard (C89, to play safe). These are aAbBcdHIjmMpSUwWxXyYZ%. But even then, the results of some of the conversion specifiers are non-portable.
aAbBcdHIjmMpSUwWxXyYZ%
Returns the strings to be used to represent Standard time (STD) respectively Daylight Savings Time (DST).
tzset(); my ($std, $dst) = tzname;
Set-up local timezone from $ENV{TZ} and the OS.
$ENV{TZ}
CLK_TCK CLOCKS_PER_SEC NULL
TXNAME_MAX
This module is part of POSIX-1003 distribution version 0.06, built on December 25, 2011. Website: http://perl.overmeer.net. The code is based on POSIX, which is released with Perl itself.
Copyrights of the perl code and the related documentation by 2011 by Mark Overmeer. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html
To install POSIX::1003, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POSIX::1003
CPAN shell
perl -MCPAN -e shell install POSIX::1003
For more information on module installation, please visit the detailed CPAN module installation guide.