Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Epoch time conversion in CSV

by tobyink (Abbot)
on Sep 25, 2012 at 15:44 UTC ( #995578=note: print w/ replies, xml ) Need Help??


in reply to Epoch time conversion in CSV

For parsing and writing CSV, Text::CSV is your friend. And for datetime manipulations, you want DateTime.

use Text::CSV; use DateTime; use constant DATE_FORMAT => '%a %b %d %Y %T'; my $in_fh = \*DATA; my $out_fh = \*STDOUT; my $csv = Text::CSV->new({ allow_whitespace => 1 }); while (my $row = $csv->getline($in_fh)) { for my $col (0, 1) { my $dt = DateTime->from_epoch( epoch => $row->[$col], time_zone => '-05:00', ); $row->[$col] = $dt->strftime(DATE_FORMAT); } $csv->print($out_fh, $row); print {$out_fh} "\n"; } __DATA__ 1345752662, 1345752673, CLOSED, CRITICAL, Other fields etc
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: Epoch time conversion in CSV
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2014-10-30 13:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls