Splitting Time : date time « Data Type « Perl






Splitting Time

  

#!/usr/bin/perl
use warnings;
use strict;
my ($hours, $minutes, $seconds) = secs2hms(3723);
print "3723 seconds is $hours hours, $minutes minutes and $seconds seconds";
print "\n";
sub secs2hms {
    my ($h,$m);
    my $seconds = shift;
    $h = int($seconds/(60*60)); $seconds %= 60*60;
    $m = int($seconds/60); $seconds %= 60;
    ($h,$m,$seconds);
}

   
    
  








Related examples in the same category

1.To extract the current date by using time and localtime
2.Set the value of localtime to a scalar variable, you'll get a typical UNIX-style time
3.scalar(localtime(time()))
4.Create new time based on the value from localtime
5.Print out the current time in standard time
6.Is leap year subroutine
7.Execute date command and get user input
8.Time of Day
9.Switch Time
10.Converting Time
11.Splitting Local Time
12.localtime converts a time into the local time.
13.gmtime function converts a time value into Greenwich Mean Time