Solved

How to return time string includes mini-seconds?

Posted on 1997-07-13
4
182 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now