1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PERL - convert date back to epoch

Discussion in 'Programming' started by dakar, Jan 9, 2007.

  1. #1
    I've spent two days searching the net and perl archive... you name it, and come up blank.

    Here's my problem, I've got 10's of thousands of log files that need to be imported into RRDtool to graph things out nice and pretty... not too big an issue, however the log files being created are generated by a binary that I can't edit to change the way that data is timestamped in this case with a date and time that is in standard human readable format... What I'm looking for is a formula that can convert this back into epoch time.

    To top it off most of the logs are created after the fact so file creation time is useless as well...however I was able to change the output files to include the date/time of the metrics contained in the logfile into the filename.

    Forexample log1.200612291200, splitting after the . gives me the date/time that I want to convert;

    So a timestamp of 200612291200 is what needs to be converted back into back into epoch time (which is 1164996000).

    I've found a javascript snippet that will do it, not practical for mass use, but can't sort out a perl method that will yield the same results.

    I'm sure there has to be a perl module or something out there, but it's eluding me at.

    Anyone got any ideas?
     
    dakar, Jan 9, 2007 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    TwistMyArm, Jan 9, 2007 IP
  3. blfast

    blfast Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You want Time::Local
    perldoc Time::Local (or search online)
     
    blfast, Jan 26, 2007 IP
  4. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You just want 'mktime' and POSIX:
    
    use POSIX;
    
    my $unixtime = mktime ($sec, $min, $hour, $day, $mon, $year, $wday, $yday);
    Code (markup):
    HTH, cheers!
     
    picouli, Jan 26, 2007 IP