CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
time function for perl under unix

 



mamo
Novice

May 28, 2002, 5:02 AM

Post #1 of 2 (698 views)
time function for perl under unix Can't Post

Hi
Does anyone know where i can find a function which transfer i.e "22.05.2002 15:20:25" dd.mm.yyyy
hh:minmin:secsec" format in a second since 1 of January 1970 00:00:00.

thanks


fashimpaur
User

May 28, 2002, 5:53 AM

Post #2 of 2 (695 views)
Re: [sileshi] time function for perl under unix [In reply to] Can't Post

sileshi,

How's this:


Code
  

use
Date::Calc qw( Delta_DHMS );

my $inputtime = "22.05.2002 15:20:25";
my ($date, $time) = split(/ /, $inputtime);
my ($day, $mon, $year) = split(/\./, $date);
my ($hh, $mm, $ss) = split(/:/, $time);
my $secondsInMinute = 60;
my $secondsInHour = 3600;
my $secondsInDay = 24 * $secondsInHour;

my ($epochDD, $epochMM, $epochYYYY, $epochhh, $epochmm, $epochss) = qw( 1 1 1970 0 0 0 );

my ($deltaDD, $deltahh, $deltamm, $deltass) =
Delta_DHMS($epochYYYY,$epochMM,$epochDD,$epochhh,$epochmm,$epochss,$year,$mon,$day,$hh,$mm,$ss);
my $timeSinceEpoch = ($deltaDD * $secondsInDay) + ($deltahh * $secondsInHour) + ($deltamm * $secondsInMinute) + $deltass;

print (join(", ", ($deltaDD, $deltahh, $deltamm, $deltass))."\n");
print ($timeSinceEpoch,"\n");

print gmtime($timeSinceEpoch)."\n";

# as a function:

sub toEpoch ($){
use Date::Calc qw( Delta_DHMS );
my $inputtime = shift;
my ($date, $time) = split(/ /, $inputtime);
my ($day, $mon, $year) = split(/\./, $date);
my ($hh, $mm, $ss) = split(/:/, $time);
my $secondsInMinute = 60;
my $secondsInHour = 3600;
my $secondsInDay = 24 * $secondsInHour;
my ($epochDD, $epochMM, $epochYYYY, $epochhh, $epochmm, $epochss) = qw( 1 1 1970 0 0 0 );
my ($deltaDD, $deltahh, $deltamm, $deltass) =
Delta_DHMS($epochYYYY,$epochMM,$epochDD,$epochhh,$epochmm,$epochss,$year,$mon,$day,$hh,$mm,$ss);
my $timeSinceEpoch = ($deltaDD * $secondsInDay) + ($deltahh * $secondsInHour) + ($deltamm * $secondsInMinute) + $deltass;
return $timeSinceEpoch;
}

# use of function:
my $epochSeconds = toEpoch("22.05.2002 15:20:25");
print $epochSeconds."\n";
print gmtime($epochSeconds)."\n";


Hope that helps.
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives