How to find the Greenwich Mean time in Perl?

Posted by Joys of Programming on in Perl

Using localtime, you can find the local time. But to find the greenwich mean time also known as GMT, you must make use of the function gmt.


my $time = time();

my ($sec, $min, $hours, $mday, $month, $year, $wday, $yday, $isdst) = gmtime($time);

my @day = qw (Sunday Monday Tuesday Wednesday Thursday Friday Saturday);

my @month_name = qw (January February March April May June July August Spetember October November December);

print $day[$wday], " ",$month_name[$month], " ",$mday," ", $hours,":",$min,":",$sec, " ",1900+$year," GMT\n"

which generates the following output


Monday November 23 14:29:32 2009 GMT

Reblog this post [with Zemanta]


Tags: , , ,

Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.