Free as Freedom, not Free as Free Pizza!” />


Udruženje Informatičara BiH - Cross-platform and Portable Development With PHP, LAMP/WAMP development, AJAX and Javascript, ASP, dot NET, C sharp, C++, C, VB, Oracle, tutorials and tips...
Free as Freedom, not Free as Free Pizza!


Add to Google

Sunday, October 29, 2006

Perl's localtime()

Perl’s localtime function returns nine element list representing:
*[0] System Seconds
*[1] System Minutes
*[2] System Hours
*[3] System Day
*[4] System Month
*[5] System number of years since 1900
*[6] System number of days since Sunday
*[7] System number of days since the start of the year
*[8] Whether or not daylight savings is active

Short and easy way to get today’s date/time is:
my @local = (localtime)[1..5];
my $today = sprintf "%4d-%02d-%02d-%02d-%02d", $local[4] + 1900, $local[3] +1, $local[2], $local[1], $local[0];
my @local = (localtime)[1..5]; declares array local and assigns minutes [1], hours [2], day [3], month [4], and year [5] to it. my $today = sprintf "%4d-%02d-%02d-%02d-%02d", $local[4] + 1900, $local[3] +1, $local[2], $local[1], $local[0]; joins all elements of local into $today. sprintf formats elements, for example %4d converts $local[4] + 1900 or year into 4 %4d decimals.
For more information visit: