Solved

How to return time string includes mini-seconds?

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.

759 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

18 Experts available now in Live!

Get 1:1 Help Now