Perl Programming/Keywords/gmtime

Previous: glob Keywords Next: goto

The gmtime keyword

edit

gmtime works similar to localtime, except that the returned values are localized for the standard Greenwich Time Zone. If EXPRESSION has been omitted, content of $_ is used instead. When called in list context, the last value returned by gmtime ($isdst: is daylight saving time) is always 0, as there is no daylight saving time for GMT.

Syntax

edit
  gmtime EXPRESSION
  gmtime

Examples

edit
  The code
($s, $min, $h, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);

$year += 1900;

print $isdst . " " . $yday . ". day of the year, " . $wday . ". day of the week\n";
print $year . '-' . qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon] . '-' . $mday . ' ' . $h . ':' . $min . ':' . $s . "\n";
($s, $min, $h, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime(time);

$year += 1900;

print $isdst . " " . $yday . ". day of the year, " . $wday . ". day of the week\n";
print $year . '-' . qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon] . '-' . $mday . ' ' . $h . ':' . $min . ':' . $s . "\n";
returns on Windows something like:
0 47. day of the year, 2. day of the week
2015-Feb-17 16:15:30
0 47. day of the year, 2. day of the week
2015-Feb-17 15:15:30

Note that daylight saving time is not present in February.

See also

edit
gmtime localtime time times utime
Previous: glob Keywords Next: goto