Solved

How to return time string includes mini-seconds?

Posted on 1997-07-13
4
186 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:kenysc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:julio011597
ID: 1829057
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
0
 

Author Comment

by:kenysc
ID: 1829058
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
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1829059
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
0
 

Accepted Solution

by:
gambito042797 earned 50 total points
ID: 1829060
With the permission of the other people, I think this can solve your question:

You can make use of the gettimeofday function.
Here is its declaration:

#include <time.h>

int gettimeofday (struct timeval *tp, struct timezone *tzp);

where timeval is:

struct timeval
{

unsigned long tv_sec;  /* seconds since 1, 1 1970 */
long   tv_usec;  /* Microseconds. Between 0 and 999.999 */

};

struct timezone
{

int tz_minuteswest; /* Local time variation in minutes, in relation to GMT */

int tz_dsttime; /* Saving daylights correction */

}

Also existing:

settimeofday ( struct timeval *tp, struct timezone *tzp);

}

Returned value: 0 if OK, -1 if not


0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question