Re: Script Help

Athan <[email protected]> Mon, 5 Jul 2010 16:01:11 +0100
Newsgroups gmane.network.irc.irssi.user
Message-ID <[email protected]>
On Mon, Jul 05, 2010 at 09:32:36AM -0500, Tamara Temple wrote:
>   if (hour > 12) {
>     $hour -= 12;
>     $daypart = "PM";
>   } else {
>     $daypart = "AM";
>   }
>
> and add in an indicator if it's AM or PM.
>
> Also, you can accomplish the formatting to $thetime with a single  
> sprintf() function call rather than making a whole lot of function calls 
> and concatenating them together:
>
>   $thetime = sprintf("!msg %02d.%02d.%02d %02d-%02d-%02d",
>        $hour, $min, $sec, $mday, $mon+1, $year+1900);

  Or you could just do the far more sensible:

use POSIX qw(strftime);

$thetime = strftime("%H:%M:%S %d-%m-%Y", localtime);

That's 24 hour format, check 'man strftime' for the format specifiers
for 12 hour and am/pm.  You probably want to include some indication of
timezone as well, IRC being an international thing (that'd be %z or %Z
in strftime).

-- 
- Athanasius = Athanasius(at)miggy.org / http://www.miggy.org/
                  Finger athan(at)fysh.org for PGP key
	   "And it's me who is my enemy. Me who beats me up.
Me who makes the monsters. Me who strips my confidence." Paula Cole - ME