logan has asked for the wisdom of the Perl Monks concerning the following question:
It seems to me that I'm using three lines of code to do something that should be fairly basic and that using sprintf to trim microseconds into milliseconds is a complete hack. Moreover, the docs for gettimeofday() continually refer to the value returned as "milliseconds", which implies a three-digit number (thousandths of a second). I suspect that there's a better way to do this but I'm kind of stumped.use Time::HiRes qw(gettimeofday); $one = gettimeofday; print STDOUT "one = $one\n"; ($sec,$milli) = gettimeofday; print STDOUT "sec = $sec, milli = $milli\n"; $milli2 = sprintf("%.*s", 3, $milli); print STDOUT "sec = $sec, milli = $milli, milli2 = $milli2\n"; $time = join ('',$sec,$milli2); print STDOUT "time = $time\n"; Output: one = 1227582343.55258 sec = 1227582343, milli = 552702 sec = 1227582343, milli = 552702, milli2 = 552 time = 1227582343552
-Logan
"What do I want? I'm an American. I want more."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Epoch time in milliseconds: Is there a better way?
by GrandFather (Saint) on Nov 25, 2008 at 03:37 UTC | |
by logan (Curate) on Nov 25, 2008 at 06:08 UTC | |
by Xilman (Hermit) on Nov 25, 2008 at 12:31 UTC | |
by logan (Curate) on Nov 25, 2008 at 20:34 UTC | |
by GrandFather (Saint) on Nov 25, 2008 at 06:42 UTC |