Solved

Easy - Formatting the Time

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl match and sort unique result 2 137
Removing file extension within a file. 4 94
transpose into pipe delemited 8 69
File Find regex problem 4 62
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

809 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