Solved

Easy - Formatting the Time

Posted on 1998-11-05
4
192 Views
Last Modified: 2010-03-04
Hi!
Here's an easy one:
How can I stick the time into a variable, and also make it in regular looks - i.e. 10:30 PM

Thanks,
Mark
0
Comment
Question by:eversoslightly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 10 total points
ID: 1206012
200 different ways to do it.... Here's one

my($sec, $min, $hour) = localtime;
my($t) = 'A';
if (!$hour) {
    $hour = 12;
} elsif ($hour > 12) {
    $t = 'P';
    $hour -= 12;
} elsif ($hour = 12) {
   $t = 'P';
}

printf("The time is %0.2d:%0.2d:%0.2d\n",$hour,$min,$sec);

0
 
LVL 84

Expert Comment

by:ozo
ID: 1206013
#another:
use POSIX;
print strftime"%I:%M %p\n",localtime;
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1206014
OK, then I'll see your posix, and raise you

use Date::Manip;

print UnixDate('now', "%I:%M:%S %p"),"\n";

0
 
LVL 1

Author Comment

by:eversoslightly
ID: 1206015
Thanks :)  Only needed one :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question