CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Adjusting the Time

 



asifiqbal
Novice

Dec 9, 2010, 7:43 AM

Post #1 of 4 (665 views)
Adjusting the Time Can't Post

Hi

I want to add certain number of hours, minutes and seconds to the time retrieved from a text file.Right now i have written my own logic to add 1 minute when the second exceeds 60 and the same goes to hours and minutes.
The problem comes when introducing zero infront of hours minutes and seconds when it's value is less than 10.

01:01:01

Is there any perl function available to do this?


Zhris
User

Dec 9, 2010, 11:16 AM

Post #2 of 4 (659 views)
Re: [asifiqbal] Adjusting the Time [In reply to] Can't Post

Hi,

sprintf to format a number / string:

Code
my $time = sprintf ("%02d:%02d:%02d", $hour, $min, $sec);


The Date::Calc module provides methods to perform time and date based calculations (Add_Delta_DHMS to add days,hours,mins,secs to a time):

Code
use Date::Calc qw(Add_Delta_DHMS); 
my ($sec, $min, $hour, $day, $mon, $year) = gmtime();
my ($year2, $mon2, $day2, $hour2, $min2, $sec2) = Add_Delta_DHMS($year + 1900, $mon + 1, $day, $hour, $min, $sec, "0", "1", "4", "0");
printf ("%02d/%02d/%04d - %02d:%02d:%02d\n", $day2, $mon2, $year2, $hour2, $min2, $sec2);


Chris


(This post was edited by Zhris on Dec 9, 2010, 11:20 AM)


BillKSmith
Veteran

Dec 9, 2010, 12:37 PM

Post #3 of 4 (649 views)
Re: [asifiqbal] Adjusting the Time [In reply to] Can't Post

 What us different between this question and the one you asked last month http://perlguru.com/gforum.cgi?post=50282?
Good Luck,
Bill


asifiqbal
Novice

Dec 9, 2010, 2:48 PM

Post #4 of 4 (641 views)
Re: [Zhris] Adjusting the Time [In reply to] Can't Post

Yes, i am concerned about month day hour mins secs but not year and i want to store back again the adjusted date to the CSV file, and also i need to combine hour minute and second together in a single variable before storing back to the file

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives