Perl gmtime Function



This function returns a list of values corresponding to the date and time as specified by EXPR, or date and time returned by the time function if EXPR is omitted, localized for the standard Greenwich mean time. The values returned are as follows −

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);

All list elements are numeric, and come straight out of the C `struct tm'. $sec, $min, and $hour are the seconds, minutes, and hours of the specified time. $mday is the day of the month, and $mon is the month itself, in the range 0..11 with 0 indicating January and 11 indicating December. $year is the number of years since 1900. That is, $year is 123 in year 2023. $wday is the day of the week, with 0 indicating Sunday and 3 indicating Wednesday. $yday is the day of the year, in the range 0..364 (or 0..365 in leap years). $isdst is always 0 .


Following is the simple syntax for this function −

gmtime EXPR


Return Value

This function returns a string of the form: Thu Sep 21 14:52:52 2000 in scalar context and in list context the individual time component values (seconds, minutes, hours, day of month, month, year, day of week, day of year, daylight savings time).


Following is the example code showing its basic usage −


@weekday = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

$local_time = gmtime();

print "Local time = $local_time\n";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
$year = $year + 1900;
print "Formated time = $mday/$mon/$year $hour:$min:$sec $weekday[$wday]\n";

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

Local time = Sun Sep  1 09:06:41 2013
Formated time = 1/8/2013 9:6:41 Sun