hyans.milis has asked for the wisdom of the Perl Monks concerning the following question:
hi,
any idea how to change the time format from below data on 3rd & 4th column into milisecond (epoch), bcoz currently Datetime package is not installed in my machine.
source ALL30 2191967708 201211020915 201303020923
expected result ALL30 2191967708 1351822500000 1362190980000
thanks#!/usr/bin/perl use strict; use warnings; use DateTime; use DateTime::Format::Strptime; my $file = $ARGV[0] or die "Need to get CSV file on the command line\n +"; my $outfile = "output_date.txt"; my $sum = 0; open(my $data, '<', $file) or die "Could not open '$file' $!\n"; open (OUTFILE, "> $outfile") || die "ERROR: opening $outfile\n"; while (my $line = <$data>) { chomp $line; my @fields = split "\t" , $line, -1;; my $formatter= new DateTime::Format::Strptime(pattern => '%Y%m +%d%T'); my $sum1 = "$formatter->parse_datetime($fields[2])"; my $sum2 = "$formatter->parse_datetime($fields[3])"; $fields[2] = "$sum1"; $fields[3] = "$sum2"; # $line= print join( "\t", @fields ) . "\n" ; print OUTFILE "@fields\n"; } close ($data); close (OUTFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: change the time format into milisecond
by CountZero (Bishop) on Mar 14, 2013 at 16:12 UTC | |
|
Re: change the time format into milisecond
by Not_a_Number (Prior) on Mar 14, 2013 at 21:20 UTC |