in reply to adding time variables together
#!/usr/bin/perl -w use strict; use POSIX qw(strftime); my $now = time(); #Gets current time # Subtract 3 hours, 15 minutes #(seconds/per minute * minutes/per hour * 3) = 3 hours # plus # (seconds/per minute * 15) my $earlier = $now - ((60 * 60 * 3) + (60 * 15)); # Format the times using POSIX module $now = strftime "%H:%M", localtime($now); $earlier = strftime "%H:%M", localtime($earlier); print "The current time is $now\nThe earlier time is $earlier\n";
=Output The current time is 15:40 The earlier time is 12:25
If you have to store your time in the HH:MM format, just follow Masem's excellent advice...
Rich36
|
|---|