Solved

How to return time string includes mini-seconds?

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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