Link to home
Start Free TrialLog in
Avatar of kenysc
kenysc

asked on

How to return time string includes mini-seconds?

I wish to have a time string ($t) like the one got by
$t = time();
However, it only returns nearest to seconds. How about mini-seconds?

Thanks in advance.
Avatar of julio011597
julio011597

There should not be anything like that.

If your purpose is something like timing a process, try to have a look at the function 'times':

"this function returns a four-element array giving the user and system CPU times, in seconds (possibly fractional), for this process and the children of this process".

($user, $system, $cuser, $csystem) = times;

Example:

--//--
$start = (times)[0];
... # code to time
$end = (times)[0];
printf "that took %.2f CPU seconds\n", $end - $start;
--//--

If this answers your question, please let me re-submit it as an answer.

Rgds, julio
Avatar of kenysc

ASKER

I really wish to get the time in detailed but not timing a program (I know of times()). In fact I wish to generate filenames that never be the same so I think of using the time strings to be the filenames.

Thanks very much for your comment.

ken
Why not just appending the fractional part of the CPU time elapsed since the start of the script, to the time string you get from time().

This will end up with a string which will not tell you the correct time of creation (at least in its fractional part), but will surely make up unique file names.

-julio
ASKER CERTIFIED SOLUTION
Avatar of gambito042797
gambito042797

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial