GMT Time in Perl

PERLServer Side ProgrammingProgramming Scripts

The function gmtime() in Perl works just like localtime() function but the returned values are localized for the standard Greenwich time zone. When called in list context, $isdst, the last value returned by gmtime, is always 0. There is no Daylight Saving Time in GMT.

You should make a note on the fact that localtime() will return the current local time on the machine that runs the script and gmtime() will return the universal Greenwich Mean Time, or GMT (or UTC).

Try the following example to print the current date and time but on GMT scale −

Example

 Live Demo

#!/usr/local/bin/perl
$datestring = gmtime();
print "GMT date and time $datestring\n";

Output

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

GMT date and time Sat Feb 16 13:50:45 2013
raja
Published on 29-Nov-2019 06:30:24
Advertisements