Perl time Function



Description

This function returns the number of seconds since the epoch (00:00:00 UTC, January 1, 1970, for most systems; 00:00:00, January 1, 1904, for Mac OS). Suitable for feeding to gmtime and localtime.

Syntax

Following is the simple syntax for this function −

 time 

Return Value

This function returns integer, seconds since epoch.

Example

Following is the example code showing its basic usage −

 #!/usr/bin/perl -w @weekday = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); $retval = time(); print "Return time is $retval\n"; $local_time = gmtime( $retval); print "Local time = $local_time\n"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time); $year = $year + 1900; $mon += 1; print "Formated time = $mday/$mon/$year $hour:$min:$sec $weekday[$wday]\n"; 

When above code is executed, it produces the following result −

 Return time is 1176831539 Local time = Tue Apr 17 17:38:59 2007 Formated time = 17/4/2007 17:38:59 Tue 
perl_function_references.htm
Advertisements