in reply to Is there a better way to print time in a HH:MM:SS format than sprintf

There's strftime in core module POSIX. It takes a format string and the output of gmtime or localtime as input.

Replies are listed 'Best First'.
Re^2: Is there a better way to print time in a HH:MM:SS format than sprintf
by gargle (Chaplain) on Feb 03, 2006 at 07:17 UTC

    I thought about using strftime but it would give me the same 'problem': provide a format string

    I was looking actually for a module that would show HH:MM:SS by default.

    --
    if ( 1 ) { $postman->ring() for (1..2); }

      Well, the POSIX::strftime way is shorter than printf:

      use POSIX; print strftime("%H:%M:%S", localtime);
      since time (i.e. Now) is the default for localtime. And if you wrap this into a sub, its usage is even shorter:
      sub TimeHMS { my $time = scalar(@_) ? shift(@_) : time; return strftime( "%H:%M:%S", localtime($time) ); } # TimeHMS print TimeHMS();

      Best regards,
      perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"