in reply to seconds into a date

localtime takes a number of seconds since the epoch (usually 1st Jan 1970) and returns information about the date and time.

For more complex requirements, I recommend looking at DateTime.

#!/usr/bin/perl use strict; use warnings; use DateTime; # 1st Jan 2000 my $date = DateTime->new(year => 2000, month => 1, day => 1); # Add a million seconds $date->add(seconds => 1_000_000); # See what you get - 2000-01-12T13:46:40 print $date;

Update: Actually you can also do something similar using only modules from the standard distribution.

#!/usr/bin/perl use strict; use warnings; use Time::Local; # Warning: The parameters to timelocal can be a bit confusing # Read the documentation carefully my $date = timelocal(0, 0 , 0, 1, 0, 100); $date += 1_000_000; print scalar localtime $date;
--

See the Copyright notice on my home node.

Perl training courses

Replies are listed 'Best First'.
Re^2: seconds into a date
by Spooky (Beadle) on Jul 02, 2009 at 08:57 UTC
    ..thanks so much 'davorg' - your first response worked great and I'll try your update as well as look at DateTime although that looks like quite a bit of documentation... again, thanks....