Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to get time in perl?

by trammell (Priest)
on Jul 07, 2005 at 01:39 UTC ( [id://472992]=note: print w/replies, xml ) Need Help??


in reply to How to get time in perl?

Just call localtime in scalar context:
my $foo = localtime; print $foo;

Update: Drat. Indeed the output from localtime follows the ctime() format, which does not include AM/PM. It does return a 24-hour time, but that's not what the OP wanted.

Replies are listed 'Best First'.
Re^2: How to get time in perl?
by GrandFather (Saint) on Jul 07, 2005 at 01:47 UTC

    or indeed:

    print scalar localtime;

    Perl is Huffman encoded by design.

      Nice, has that always worked in Perl 5 or is it a feature of newer Perl versions ?

      There is one problem, the OP explicitly asked for AM/PM in the output, this does not give me that. Perhaps it does in some locales?

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!

        Ouch. OP did ask for AM/PM, but I simply replied to trammell's post and didn't notice that part.

        I'm a newbie to Perl (about 3 months) so I don't know how long you may have been able to do that with localtime. I presume for as long as localtime has been around.

        scalar has been around for a fair while. Scalar and List context are fairly fundamental to Perl.


        Perl is Huffman encoded by design.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://472992]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-25 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found