Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to return time string includes mini-seconds?

Posted on 1997-07-13
4
Medium Priority
?
190 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 150 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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.

721 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