Solved

Easy - Formatting the Time

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

15 Experts available now in Live!

Get 1:1 Help Now