I have a time of format 2013-04-29 08:17:58
and I need to convert it into seconds.
In UNIX, we can use date +%s
. Is there anyway to do it in Solaris?
I have a time of format 2013-04-29 08:17:58
and I need to convert it into seconds.
In UNIX, we can use date +%s
. Is there anyway to do it in Solaris?
Use Time::Piece
. It has been part of the standard Perl 5 distribution since version 9.5 and shouldn't need installing.
use strict;
use warnings;
use 5.010;
use Time::Piece;
my $t = '2013-04-29 08:17:58';
$t = Time::Piece->strptime($t, '%Y-%m-%d %H:%M:%S');
say $t->epoch;
output
1367223478
With a little more effort, you can do this with your horribly outdated version of Perl.
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
my $str = '2013-04-29 08:17:58';
my @dt = split /[- :]/, $str;
$dt[0] -= 1900;
$dt[1] -= 1;
print timelocal reverse @dt;
Time::Local has been included with Perl since the first release of Perl 5 (in 1994).
But please do what you can to get your ancient version of Perl updated.
Update: Getting a few downvotes on this. But no-one has bothered to explain why.