For ex : from date : 10/02/2010
How to convert equal time stamp for 10/02/2010 00:00:00
in Perl
I cant use local time or time .. is there any other way to achieve this ..
For ex : from date : 10/02/2010
How to convert equal time stamp for 10/02/2010 00:00:00
in Perl
I cant use local time or time .. is there any other way to achieve this ..
Without localtime():
use Time::Local;
$time = timelocal($sec,$min,$hour,$mday,$mon,$year);
( see perldoc )
A standard way would be something like:
use POSIX;
use strict;
use warnings;
my $sec = 0;
my $min = 0;
my $hour = 0;
my $day = 10;
my $mon = 2 - 1;
my $year = 2010 - 1900;
my $wday = 0;
my $yday = 0;
my $unixtime = mktime ($sec, $min, $hour, $day, $mon, $year, $wday, $yday);
print "$unixtime\n";
my $readable_time = localtime($unixtime);
print "$readable_time\n"
( From http://www.adp-gmbh.ch/perl/posix/convert_time.html )
The DateTime module should be helpful here. In particular, I believe the DateTime::Format::Natural module can parse a user-supplied date string. From there, you have a DateTime object and can print it out or transform it as you like.
Depending on where your initial date is coming from you might be able to parse it using
Date::Manip
and calling
ParseDate("10/02/2010")
You can then take that output and convert it into whatever format you wish.
You could use Date::Parse:
use Date::Parse;
print str2time('10/02/2010 00:00:00');
On my machine this prints 1285970400, which corresponds to October 2nd, 2010 (I live in +1 GMT with +1 Wintertime.)
You can use the Time::Local core module:
use Time::Local;
my ($d, $m, $y) = split '/', '10/02/2010';
my $time = timelocal(0,0,0,$d,$m,$y);