Convert Date from EPOC to datestamp (PERL)

SafeSql
SafeSql used Ask the Experts™
on
how do I convert a date from EPOC time to a date stamp?
for instance 1039216472 to YYYY/MH/DD HH:MM:SS  

I have only perl or borne shell available in the execution area but I can install modules.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007
Commented:
The simplest way is:

use POSIX qw(strftime);
my $time='1039216472';
print strftime "%Y/%m/%d %T\n", localtime($time);

If you don't want to use the POSIX module (which is standard), the equivalent is:


my $time='1039216472';
my ($sec,$min,$hour,$day,$mon,$year) = (localtime($time))[0..5];
printf("%d/%02d/%02d %d:%d:%d\n", $year+1900, $mon+1, $day, $hour, $min, $sec);


Top Expert 2007

Commented:
The simplest way is:

use POSIX qw(strftime);
my $time='1039216472';
print strftime "%Y/%m/%d %T\n", localtime($time);

If you don't want to use the POSIX module (which is standard), the equivalent is:


my $time='1039216472';
my ($sec,$min,$hour,$day,$mon,$year) = (localtime($time))[0..5];
printf("%d/%02d/%02d %d:%d:%d\n", $year+1900, $mon+1, $day, $hour, $min, $sec);


Top Expert 2007

Commented:
RVSP.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial