Solved

Easy - Formatting the Time

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
remove duplicates from the csv file 13 124
Need Helping Editing Perl Script for PowerChute Network Shutdown 3 98
Export Variables in Perl 3 123
perl syntax 3 54
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

738 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