On 05/07/2010 11:02, Dave Cross wrote:
On 07/05/2010 06:46 AM, Dave Cross wrote:
On 07/05/2010 04:19 AM, Lyle wrote:
POSIX::strftime is your friend.

$ perl -MPOSIX=strftime -E'say strftime "%Y-%m-%d %H:%M:%S %z", localtime'
2010-07-05 06:44:39 +0100
On further reflection, it strikes me that my output isn't exactly what
you asked for. You wanted the timeszone as "+01:00" and I gave you "+0100".

The command line "date" command has the "%:z" escape sequence that gives
what you want.

   $ date +%:z
   +01:00

But that's apparently not supported by POSIX.pm.

   $ perl -MPOSIX=strftime -E'say strftime "%:z", localtime'
   %:z

But there's still no need to resort to the coding pyrotechnics you used
above when a simple substitution fixes the problem.

   #!/usr/bin/perl

   use strict;
   use warnings;
   use 5.010;

   use POSIX qw[strftime];

   $_ = strftime '%Y-%m-%d %H:%M:%S %z', localtime;

   s/(\d\d)$/:$1/;

   say; # 2010-07-05 11:01:33 +01:00

You know I looked at use POSIX qw[strftime], but didn't find the perldoc that helpful:-
http://perldoc.perl.org/POSIX.html
Maybe a patch with some more examples is in order? Or a link explaining the format? When I looked at it with tired eyes |aAbBcdHIjmMpSUwWxXyYZ% made me think that learning what/how to use the symbols was going to take longer than hacking some dirty code together...|

Perhaps more worrying is google on strftime brings up
http://php.net/manual/en/function.strftime.php
Which actually covers it well... also /%z would seem to vary a little depending on OS...

Which raises another question, should perldoc get a comments section like mysql and others? After all, the easier you make it for people to contribute, the more contributions you get.

/
Lyle

_______________________________________________
BristolBathPM mailing list
[email protected]
http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm

Reply via email to