Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday September 18, 2008
11:50 AM

DateTime and &Time::Hires::time

[ #37486 ]

After a bit of work, I finally got DateTime to recognize the time value from Time::HiRes and format it correctly for my test database.

#!/usr/bin/env perl

use strict;
use warnings;

use DateTime;
use aliased 'DateTime::Format::Strptime';

# 2008-09-18T16:00:20
my $format = Strptime->new( pattern => "%FT%H:%M:%S.%5N" );

# this is the format that Time::HiRes will return the time()
my $datetime = DateTime->from_epoch( epoch => 1221753628.79859 );
$datetime->set_formatter($format);
print $datetime;
__END__
2008-09-18T16:00:28.79858

You can actually get finer granularity from Time::HiRes, but my god, this is for the start and end of each test program. You won't need finer granularity than this.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.