taint has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, Monks.

I've been attempting to get localtime returned in w3c time format. eg; with either the DateTime::Format::W3CDTF, or DateTimeX::Web Modules. For the life of me, I can't get either to work. I'm probably just over complicating it. Any examples would be greatly appreciated.
Thanks.

--Chris

#!/usr/bin/perl -Tw
use Perl::Always or die;
my $perl_version = (5.12.5);
print $perl_version;
  • Comment on Anyone know how to get DateTime::Format::W3CDTF, or DateTimeX::Web to print localtime?

Replies are listed 'Best First'.
Re: Anyone know how to get DateTime::Format::W3CDTF, or DateTimeX::Web to print localtime?
by kcott (Archbishop) on Nov 27, 2013 at 08:38 UTC

    G'day Chris,

    Including other bits of information I picked up in this thread, consider this:

    #!/usr/bin/env perl -l use strict; use warnings; use Time::Piece; print localtime->strftime('%Y-%m-%dT%H:%M:%S');

    Output:

    2013-11-27T19:31:52

    -- Ken

      Good call, kcott.
      And wastes less ACSII too.
      Thanks. :)

      --Chris

      #!/usr/bin/perl -Tw
      use Perl::Always or die;
      my $perl_version = (5.12.5);
      print $perl_version;
Re: Anyone know how to get DateTime::Format::W3CDTF, or DateTimeX::Web to print localtime?
by Anonymous Monk on Nov 26, 2013 at 21:26 UTC

    For the life of me, I can't get either to work. I'm probably just over complicating it.

    What code where?

    use DateTime::Format::W3CDTF; my $w3c = DateTime::Format::W3CDTF->new; my $localtime = DateTime->now( qw[ time_zone local ] ); print join "\n", $localtime->strftime( q/%F-%H:%M:%S%z/), $w3c->format_datetime( $localtime );
      "What code where?"
      If I understand that correctly; I was too embarrassed to post it.

      Your eloquent example proves (to me) I was over complicating things -- everything doesn't need to be a science project. :P

      Thanks. It was perfect.

      --Chris

      #!/usr/bin/perl -Tw
      use Perl::Always or die;
      my $perl_version = (5.12.5);
      print $perl_version;

        ...

        Its a process and a puzzle :) Sometimes you're missing a corner piece, sometimes you need a break (or a nap), this is a learning moment, so it helps to be able to answer "what was I thinking" and write that down (don't have to share , but put it in your notes) ....

        thats how checklists are born; sometimes they're general, more often they're about your thinking process; if you identify big ones, you can remember them for next time, so you'll know to take a break :) approach from a different angle ...

        :) Cheers