in reply to Attack of the killer timestamps
It seems to work (It chokes though on a year like 2202)
That is because localtime is based on the Unix concept of the number of seconds since the epoch of January 1, 1970 and has historically been represented as a 32 bit number which only goes up to the year 2038.
This may work better:
#!/usr/bin/perl use warnings; use strict; use POSIX qw/ mktime strftime /; # Get timestamp input from user print 'Enter a timestamp in mm/dd/yyyy hh:mm:ss format: '; chomp( my $stamp = <STDIN> ); my ( $month, $day, $year, $hour, $minute, $second ) = $stamp =~ m! (\d ++) / (\d+) / (\d+) \s+ (\d+) : (\d+) : (\d+) !x; # Get time value in seconds since Epoch with mktime my $now = mktime $second, $minute, $hour, $day, $month - 1, $year - 19 +00; my $realanswer = strftime '%m/%d/%Y %H:%M:%S', localtime $now + 300; print "$stamp + 5 minutes is $realanswer\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Attack of the killer timestamps
by chexmix (Hermit) on Mar 20, 2008 at 20:51 UTC | |
by mr_mischief (Monsignor) on Mar 20, 2008 at 22:11 UTC | |
by chexmix (Hermit) on Mar 21, 2008 at 13:35 UTC | |
by holli (Abbot) on Mar 20, 2008 at 22:34 UTC |