in reply to Re: How to get after 4 and 5 days date from today date
in thread How to get after 4 and 5 days date from today date
Not all days have 24 hours. Fix below. This will also give you the answer up to 23.5 hours sooner.
use POSIX qw( strftime ); sub next_day { my $start_d = (localtime)[3]; for (;;) { sleep(30*60); my $d = (localtime)[3]; return if $d != $start_d; } } next_day() for 1..5; print strftime("%Y-%m-%d\n", localtime()); next_day() for 1..4; print strftime("%Y-%m-%d\n", localtime());
Suffers from a race-condition that manifests itself if the loops is started very shortly before midnight.
|
|---|