Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Get time without seconds

by Anonymous Monk
on Mar 25, 2013 at 00:03 UTC ( #1025198=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!
I need to get the time without the seconds, does anyone here knows how I could do that using "Date::Format". Here is a code I am trying:
#!/usr/bin/perl use Time::Zone; use Date::Format; my ($today_date, $today_time) = get_timezone(); sub get_timezone { $ENV{'TZ'} = 'America/New_York'; $today_date = time2str( "%Y/%m/%d", time); # Need the time without the seconds in %r $today_time = time2str( "%r", time); return $today_date, $today_time; } print "\n Date: $today_date - $today_time \n";

Replies are listed 'Best First'.
Re: Get time without seconds
by LanX (Chancellor) on Mar 25, 2013 at 00:23 UTC
    Whats wrong with replacing %r with the appropriate placeholders for hour, minute and AM/PM but excluding seconds?

    from Date::Format

    ... %H hour, 24 hour clock, leading 0's) %I hour, 12 hour clock, leading 0's) %j day of the year %k hour %l hour, 12 hour clock %L month number, starting with 1 %m month number, starting with 01 %M minute, leading 0's %n NEWLINE %o ornate day of month -- "1st", "2nd", "25th", etc. %p AM or PM ...

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      What about this:
      $today_time = time2str( "%I:%M %p", time);
Re: Get time without seconds
by igelkott (Curate) on Mar 25, 2013 at 00:25 UTC

    Switch %r to %R

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1025198]
Approved by igelkott
[Cow1337killr]: <p>stevieb, you should leave an insightful comment at https://plugins. idea/plugin/7796- perl</p>
[Cow1337killr]: (Oops. HTML paragraph markup not needed.)
[stevieb]: Cow1337killr yeah, you're probably right. I have communicated to the author directly, and here on his threads. It's a tremenous setup. With Devel::Camelcadedb , you get full perl debug support too
[stevieb]: so now I can use CLion with the Perl plugin and have a single IDE for Perl/C/C++. It'll make writing C/XS dists much easier
[stevieb]: Python too, but I leave work at work

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2017-02-20 21:08 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (302 votes). Check out past polls.