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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seconds to EPOCH

Status
Not open for further replies.

FreeBASE

Programmer
May 3, 2002
39
US
Anyone know how to convert EPOCH seconds to a format
like 0000-00-00 00:00:00

I have reviewed several modules (Date::Calc, HTTP::Date) and can't seem to find anything that even comes close.

The only solution I have found to convert this mess is:

my $newtime = scalar localtime($epoch_time);

But this won't work in the situation I am in.

Any advice or help whould be greatly appreciated.
 
Hi,

local_time() is designed to do just that (I think) - what problem are you having? Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Using localtime the format comes out like this..

Fri May 4 01:52:14 2001

I need the format to look like this

0000-00-00 00:00:00

 
Code:
#!/usr/local/bin/perl

@d = localtime;
$d[5] += 1900;
$d[4]++;

print "DATE: $d[5]-$d[4]-$d[3] $d[2]:$d[1]:$d[0]\n";
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Or more specifically (with zero padding):
Code:
@d = localtime;
$date = sprintf("%d-%02d-%02d %02d:%02d:%02d", $d[5]+1900, $d[4]+1, $d[3], $d[2], $d[1], $d[0]);
print "$date\n";
;-)
 
If you have the Time::CTime module installed:

[tt]use Time::CTime;

print strftime("%Y-%m-%d %H:%M:%S\n", localtime);[/tt]

I'm partial to using that, since it's a bit more obvious what you're trying to print than by the array element numbers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top