Friday, January 7, 2011

get Server Time in Perl

$etime=$^T;


The variable you named $etime now contains Epoch time, which looks something like this 1140628728. Epoch time is the number of seconds since January 1, 1970. Why then? Why not.


To get the local time of your server machine:

$newetime=localtime($^T);

The variable you named $newetime now contains the time on the server in a nice neat format. (Perl's built-in localtime function took care of formatting for us.)

Wed Feb 22 12:21:51 2006


Copy and Paste Perl Code:

#!/usr/bin/perl


print "Content-type:text/html\n\n";

$etime=$^T;

$newetime=localtime($^T);

print "$etime - $newetime";

exit;

No comments: