View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Paul Evans > Time-timegm-0.01 > Time::timegm



Annotate this POD


Open  2
View/Report Bugs
Module Version: 0.01   Source  


Time::timegm - a UTC version of mktime()


 use Time::timegm qw( timegm );

 my $epoch = timegm( 0, 0, 0, 14, 6-1, 2012-1900 );

 print "2012-06-14 00:00:00 UTC happened at ",
    scalar localtime($epoch), " localtime\n";


The POSIX standard provides three functions for converting between integer epoch values and 6-component "broken-down" time representations. localtime and gmtime convert an epoch into the 6 components of seconds, minutes, hours, day of month, month and year, in either local timezone or UTC. The mktime function converts a local broken-down time into an epoch value. However, POSIX does not provide a UTC version of this.

This module provides a function timegm which has this ability.

Unlike some other CPAN implementations of this behaviour, this version does not re-implement the time handling logic internally. It reuses the mktime and gmtime functions provided by the system to ensure its results are always consistent with the other functions.


$epoch = timegm( $sec, $min, $hour, $mday, $mon, $year )

Returns the epoch integer value representing the time given by the 6 broken-down components.

As with POSIX::mktime it is not required that these values be within their "valid" ranges. This function will normalise values out of range. For example, the 25th hour of a day is normalised to the 1st hour of the following day; or the 0th month is normalised to the 12th month of the preceeding year.


The Time::Local module also provides a function called timegm() with similar behaviour to this one. The differences are:


Paul Evans <>

syntax highlighting: