some help needed..changing of time format from 12hour format to 24hour format

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2006
Posts: 9
Reputation: ivernrawks is an unknown quantity at this point 
Solved Threads: 0
ivernrawks ivernrawks is offline Offline
Newbie Poster

some help needed..changing of time format from 12hour format to 24hour format

 
0
  #1
Mar 22nd, 2006
i wana know how to change time format from 12hr format to 24 hr format..

i browsed thru many websites and cannot find the answer to it..

played around with the codes and cant get the output right..

help !
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: some help needed..changing of time format from 12hour format to 24hour format

 
0
  #2
Mar 23rd, 2006
  1. #!/usr/bin/perl
  2.  
  3. ($sec, $min, $hour, @junk) = localtime(time);
  4.  
  5. print "$hour:$min$sec\n";
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 9
Reputation: ivernrawks is an unknown quantity at this point 
Solved Threads: 0
ivernrawks ivernrawks is offline Offline
Newbie Poster

Re: some help needed..changing of time format from 12hour format to 24hour format

 
0
  #3
Mar 23rd, 2006
I have a file that contains a time in each line..
The time in each line is in 12hour format..
How to change it to 24hour format..
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: some help needed..changing of time format from 12hour format to 24hour format

 
0
  #4
Mar 23rd, 2006
like this in the file: 12:12:00? or like this: 12:12? Or like this: 12:12:00am?
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 9
Reputation: ivernrawks is an unknown quantity at this point 
Solved Threads: 0
ivernrawks ivernrawks is offline Offline
Newbie Poster

Re: some help needed..changing of time format from 12hour format to 24hour format

 
0
  #5
Mar 23rd, 2006
12:12:00 AM<- like this.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: some help needed..changing of time format from 12hour format to 24hour format

 
0
  #6
Mar 23rd, 2006
This doesn't actually change it in the file.... but it writes a new file, you can just easily change the variable on the second open to be the file it read from, however. I'm sure that Rashakil or Narue will show you a much more effecient method, but for now this works:
  1. #!/usr/bin/perl
  2.  
  3. $timefile = "times.txt";
  4. $newfile = "newtimes.txt";
  5.  
  6. open(FH, "$timefile");
  7. while (<FH>) {
  8. chomp;
  9. ($tm, $pod) = split(/ /, $_);
  10. ($hr, $min, $sec) = split(/:/, $tm);
  11. if ($pod eq "PM") {
  12. $hr = $hr + 12;
  13. $tm = "$hr:$min:$sec";
  14. } else {
  15. $tm = "$hr:$min:$sec";
  16. }
  17.  
  18. push @new_times, $tm;
  19. }
  20. close(FH);
  21.  
  22. open(FH, ">$newfile");
  23. foreach $ntime (@new_times) {
  24. print FH "$ntime\n";
  25. }
  26. close(FH);
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 9
Reputation: ivernrawks is an unknown quantity at this point 
Solved Threads: 0
ivernrawks ivernrawks is offline Offline
Newbie Poster

Re: some help needed..changing of time format from 12hour format to 24hour format

 
0
  #7
Mar 23rd, 2006
I'm confused.

Do you wanna see what's inside the text file?

Information goes as below:
Open;Nanyang Poly (527/CHYP);2565389;Opened;SW;20060224;09:01:01AM;100000756;RS_GROUP;SG FS SGP;;3738166;4992484;Medium
FW;Nanyang Poly (527/CHYP);2565389;In Planning;SW;20060224;09:01:05AM;100000756;RS_GROUP;SG FS SGP;;3738166;4992484;Medium
FW;Nanyang Poly (527/CHYP);2565389;In Planning;SW;20060224;09:01:21AM;100002324;RS_EMPLOYEE;Batalon, Mr. Michael;;3738166;4992484;Medium
FW;Nanyang Poly (527/CHYP);2565389;In Planning;SW;20060224;09:01:21AM;100002324;RS_EMPLOYEE;Batalon, Mr. Michael;;3738166;4992484;Medium
FW;Nanyang Poly (527/CHYP);2565389;Assigned;SW;20060224;09:01:26AM;100002324;RS_EMPLOYEE;Batalon, Mr. Michael;;3738166;4992484;Medium
Open;Toa Payoh (385/CHTP);2565401;Opened;SW;20060224;09:40:48AM;100000756;RS_GROUP;SG FS SGP;;3738171;4992494;Medium
FW;Toa Payoh (385/CHTP);2565401;In Planning;SW;20060224;09:40:55AM;100000756;RS_GROUP;SG FS SGP;;3738171;4992494;Medium
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 9
Reputation: ivernrawks is an unknown quantity at this point 
Solved Threads: 0
ivernrawks ivernrawks is offline Offline
Newbie Poster

Re: some help needed..changing of time format from 12hour format to 24hour format

 
0
  #8
Mar 23rd, 2006
Hey Comatose.
Just to tell you that i have solved the problem with the help of someone from elsewhere
But thanks anyway Comatose..
At least you tried to help.
Have a nice day!
Cheers!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: some help needed..changing of time format from 12hour format to 24hour format

 
0
  #9
Mar 23rd, 2006
Glad to have tried to help.... if you could have posted that information previously, I would have done a better job. Sorry for the miscommunication.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 9
Reputation: ivernrawks is an unknown quantity at this point 
Solved Threads: 0
ivernrawks ivernrawks is offline Offline
Newbie Poster

Re: some help needed..changing of time format from 12hour format to 24hour format

 
0
  #10
Mar 23rd, 2006
My bad.

Sorry for the miscommunication.

I have gotten a minor problem.

For 12:48:00 PM, it is converted to 24:48:00 hrs.

By right it should be converted to 00:48:00 hrs.

How you go about doing it?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC