in reply to DateTime normalize

I also get the same error that you get when I run your code.

I have no experience with DateTime, but looking at its POD, I notice that now() is always accessed as:

DateTime->now();

and never the way you are trying to use it:

$dt->now();

Perhaps now() (whatever it does) was never meant to be called that way? There seem to be no bug reports for this.

Replies are listed 'Best First'.
Re^2: DateTime normalize
by ikegami (Patriarch) on Aug 25, 2009 at 17:25 UTC

    Correct. now creates a new object and initialises it to the current time.

    my $dt = DateTime->now(); my $dt = DateTime->now( time_zone => 'local' );

    The OP appears to be trying to format the timestamp into a string. For this, he has a number of options.

    • He could construct the formatted timestamp himself. There are getters to get each individual components, there are getters that return the date in a couple of simple formats, and there's a getter that returns the time.

    • He could use $dt->strftime, which returns the contained date and/or time in just about any format you can imagine.

    • There's also the option of using a (parsing and) formatting helper module. These are typically named DateTime::Format::<format> (e.g. DateTime::Format::Atom).