Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

displaying microseconds from epoch like format

by r0adawg (Sexton)
on Oct 09, 2012 at 00:08 UTC ( #997898=perlquestion: print w/ replies, xml ) Need Help??
r0adawg has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks!

I'm seeking some instruction as I am learning the ins and outs of perl. I have a device that records information in microseconds using a epoch like format. I would like to be able to display the date time stamp like this : Thu Jun 10 18:15:34.155029 2010.

my record is formatted as : 1276218934.155029

my current approach is :  printf OUT1 scalar(localtime($ep_time));

I know that there must be an easy way to convert this to a readable format, similar to what I referenced above.

thank you for your help and guidance.

Comment on displaying microseconds from epoch like format
Select or Download Code
Re: displaying microseconds from epoch like format
by GrandFather (Cardinal) on Oct 09, 2012 at 00:17 UTC
    my $epTime = 1276218934.155029; my ($epoch, $frac) = $epTime =~ /(\d+)\.(\d+)/; (my $str = localtime $epoch) =~ s/(.*:\d+)/$1.$frac/; printf $str;

    Prints:

    Fri Jun 11 13:15:34.15503 2010
    True laziness is hard work
      awesome,
      changed and tweaked to work with my code:
      ($c_epoch, $frac) = $ep_time =~ /(\d+)\.(\d+)/; #courtesy of perlmonks $c_epoch += $time; # converts to local time from internal date -> $FD $str = localtime $c_epoch) =~ s/(.*:\d+)/$1.$frac/; #courtesy of perlm +onks

      produces : Thu Jun 10 07:12:02.729004 2010

      I needed the finer resolution for processing.

      again thank you!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2014-09-20 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (163 votes), past polls