Solved

Easy - Formatting the Time

Posted on 1998-11-05
4
159 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now