| | |
some help needed..changing of time format from 12hour format to 24hour format
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Re: some help needed..changing of time format from 12hour format to 24hour format
0
#2 Mar 23rd, 2006
Perl Syntax (Toggle Plain Text)
#!/usr/bin/perl ($sec, $min, $hour, @junk) = localtime(time); print "$hour:$min$sec\n";
•
•
Join Date: Mar 2006
Posts: 9
Reputation:
Solved Threads: 0
Re: some help needed..changing of time format from 12hour format to 24hour format
0
#3 Mar 23rd, 2006
Re: some help needed..changing of time format from 12hour format to 24hour format
0
#4 Mar 23rd, 2006
•
•
Join Date: Mar 2006
Posts: 9
Reputation:
Solved Threads: 0
Re: some help needed..changing of time format from 12hour format to 24hour format
0
#5 Mar 23rd, 2006
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:
Perl Syntax (Toggle Plain Text)
#!/usr/bin/perl $timefile = "times.txt"; $newfile = "newtimes.txt"; open(FH, "$timefile"); while (<FH>) { chomp; ($tm, $pod) = split(/ /, $_); ($hr, $min, $sec) = split(/:/, $tm); if ($pod eq "PM") { $hr = $hr + 12; $tm = "$hr:$min:$sec"; } else { $tm = "$hr:$min:$sec"; } push @new_times, $tm; } close(FH); open(FH, ">$newfile"); foreach $ntime (@new_times) { print FH "$ntime\n"; } close(FH);
•
•
Join Date: Mar 2006
Posts: 9
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Mar 2006
Posts: 9
Reputation:
Solved Threads: 0
Re: some help needed..changing of time format from 12hour format to 24hour format
0
#8 Mar 23rd, 2006
Re: some help needed..changing of time format from 12hour format to 24hour format
0
#9 Mar 23rd, 2006
•
•
Join Date: Mar 2006
Posts: 9
Reputation:
Solved Threads: 0
Re: some help needed..changing of time format from 12hour format to 24hour format
0
#10 Mar 23rd, 2006
![]() |
Similar Threads
- Changing Time format (Pascal and Delphi)
Other Threads in the Perl Forum
- Previous Thread: I need a short script written
- Next Thread: help me to find promoter region using perl
| Thread Tools | Search this Thread |






