Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Getting "A.M." and "P.M." with localtime $time

by Anonymous Monk
on Jul 16, 2002 at 21:40 UTC ( #182240=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Getting "A.M." and "P.M." with localtime $time

Replies are listed 'Best First'.
Re: localtime $time
by tadman (Prior) on Jul 16, 2002 at 22:58 UTC
    It's not military time. It's 24 hour notation, which is virtually a world standard. Like the metric system and coloured money.
    use POSIX 'strftime'; my $time = strftime("%r", localtime()); print $time,"\n";
    If you're getting the wrong time out, that's because your time-zone is set incorrectly. Check the output of your 'date' command, or if you're using something that uses these things they call "Control Panels", check there.
      Ooh! Ooh! Time for me to make fun of the Americans! Actually, tadman pointed out the funny part, but I shall simply point it out for all to see:

      tadman: ...virtually a world standard. Like the metric system

      What's so funny about this? Well if I recall correctly, the United States is one of the few (if not the only) country that still uses the imperial system! Update yourselves Americans and use the metric system! Heheh... I am prepared for the barrage of downvotes coming my way... one should never make fun of the out of date cool Americans!

        Time for me to make fun of the Americans!
        Um... mtk, last I checked Canada was in America. So is Mexico and the United States. If I'm not mistaken, you're from Canada. Oh well, we know what you mean. ;-)

        Update yourselves Americans and use the metric system!
        Well, we mesure soda pop bottles in liters: 3, 2, 1, .5. Our cars have KM rate measurements (as well as MPH). But, do you really think we can convert all measurements to metric? That'd be harder than change currency to the Euro.
(joshua) Re: localtime $time
by joshua (Pilgrim) on Jul 16, 2002 at 22:57 UTC
    You could use something like this...
    #!/usr/bin/perl -w use strict; use POSIX qw|strftime|; my $time = strftime('%I:%M:%S %p', localtime(time() - 60 * 60 * 2)); print "$time\n";

    Update: You didn't specify if the time was ahead or behind 2 hours. Just use time() + 60 * 60 * 2 if it's ahead.

    Joshua

Re: localtime $time
by DamnDirtyApe (Curate) on Jul 16, 2002 at 21:59 UTC

    Rather than asking us to do this for you, please show us how you are currently attempting to do it, so we can show you how to improve & correct your code.


    _______________
    D a m n D i r t y A p e
    Home Node | Email
Re: localtime $time
by FoxtrotUniform (Prior) on Jul 16, 2002 at 22:31 UTC

    Date::Calc

    CPAN is your friend; it's almost always best to look there before asking anywhere else.

    --
    The hell with paco, vote for Erudil!
    :wq

Re: localtime $time
by Cine (Friar) on Jul 16, 2002 at 22:35 UTC
    Military time? Some of us actually use these number daily ;)

    T I M T O W T D I
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2022-10-04 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (15 votes). Check out past polls.

    Notices?