Perl: Seconds Since Midnight

Some quick perl to return the number of seconds in the current day since midnight.

sub midnight_seconds {
   my @time = localtime();
   my $secs = ($time[2] * 3600) + ($time[1] * 60) + $time[0];

   return $secs;
}

The same code just written in PHP.

function midnight_seconds() {
   $secs = (date("G") * 3600) + (date("i") * 60) + date("s");
   return $secs;
}
Leave A Reply - 6 Replies
Replies
Steve McIlwaine 2006-12-29 11:34am - No Email - Logged IP: 216.26.205.58

Exactly what I needed. Thanks!

peter 2007-10-21 10:21pm - No Email - Logged IP: 209.91.60.208

Thanks for this!

Chris Radcliff 2007-12-27 04:34pm - chris.radcliff@... - Logged IP: 66.162.32.234

This came in handy. Thanks!

Darren Sharman 2008-06-01 01:31pm - No Email - Logged IP: 84.56.249.132

Nice snippet,

Cheers :-)

Steve 2009-08-27 03:10pm - No Email - Logged IP: 67.135.143.10

Great function, just what I needed for the site I am building!

Joe 2009-12-04 07:31am - No Email - Logged IP: 208.27.111.122

Awesome! Exactly what I was looking for!

All content licensed under the Creative Commons License