On Mon, Jul 5, 2010 at 11:02 AM, Dave Cross <[email protected]> wrote:
> On 07/05/2010 06:46 AM, Dave Cross wrote:
>> On 07/05/2010 04:19 AM, Lyle wrote:
>>> Hi All,
>>> I've just produced the following code, I'm sure there is a simple was
>>> to have done it, but it's very late (that's my excuse and I'm sticking
>>> to it). It works, but I thought I'd post it here for criticism.
>>>
>>> Requirement was to produce date formatted as "YYYY-MM-DD HH:MM:SS ±OO:OO".
>>>
>
>...
>
> 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
>
>
> Hope that helps,
>
> Dave...
>
Another option, depending on your environment, and still shoving the :
in at the end:
perl -le 'use DateTime; print join q{:}, split /(?=\d\d$)/,
DateTime->now->format_cldr("YYYY-MM-dd hh:mm:ss ZZZ"), 2'
I can't see a format pattern for the timezone offset that puts the : in.
Alex
_______________________________________________
BristolBathPM mailing list
[email protected]
http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm