Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert a Greenwich Mean Time to an ordinary date/time?

Status
Not open for further replies.

cyan01

Programmer
Mar 13, 2002
143
US
Hi, Experts,

Suppose I have a number which is the value returned by perl library function time, i.e.

Code:
my $utc = time;

How can I convert $utc into an ordinary datetime, e.g. mmddyyHHSS or vise versa?

Thanks!
 
Code:
(@date)=localtime(); get an array of components 
foreach (@date) {  #$date[4]++ months start at 0
  print "$_\n";    #$date[5]+=1900; 105
}
$date=localtime();  #get a scalar eg Wed Feb 23 20:53:35 2005

Also look up the Date modules on HTH
--Paul

cigless ...
 
Thank you, Paul. I guess I did not make myself clear. What I want is to find a way in perl to convert any time values in UTC format into a readable format by people.

For intance, how to convert '1101859200' into mmddyy format?

Thanks!
 
Try this:

Code:
use POSIX qw(strftime);
print strftime "%m%d%Y%H%M%S", localtime;

Output:
Code:
02232005142854
 
tweenerz,

Thank you for you posts.

However, what I want is how to convert '1101859200' into a readable format in perl?
 
you could write a function to calculate how many seconds have elapsed since Jan 1, 1970, or you could get up off your ar$e, and investigate the localtime function, use the Date::Manip modules as suggested by mlibeson (Michael), or wait for a knight in shining armour, who knows a lot about chivalry, horemanship, but feck all about Perl

The choice as they say is yours

--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top