perl: August 2008 Archives

Creating unix times from datetime stamps

| | Comments (0) | TrackBacks (0)

Scenario: you want to convert "2008-08-02 12:45:01" to the unix epoch time:

use Time::Local qw/timegm/;

my $dt = "2008-08-02 12:45:01";
my @datetime  = split /\-|:|\s/, $dt;
$datetime[1]--; # months need decrementing
my $epoch_time = timegm(reverse @datetime);

About this Archive

This page is a archive of entries in the perl category from August 2008.

perl: July 2008 is the previous archive.

perl: November 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.21-en