Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date down to milliseconds - is this possible?

Status
Not open for further replies.

aixmurderer

IS-IT--Management
Nov 28, 2000
603
NZ
Need to rename files with a date stamp (HHMMSSCC.dat), but I need more accurate than the "date" function which only seems to offer seconds as the LSB.

Any ideas? IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
in the shell, look at the timex command (I think so anyway, it's been a while)

in Perl (fancy me suggesting a Perl solution....) you have the module Time::HiRes which should do what you want Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Thanks Mike, I have managed to put together a working C program with my limited C knowledge, it gives me down to a microsecond resolution, almost an overkill of what I needed.

If interested I can post the source code here, fof what its worth.

Chris IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
Hi Chris,

Yes please. Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Here we go, don't expect any rocket science from it, it displays seconds & microseconds in the following format ssssssssss.mmmmmm (10.6 chars)

#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#include <sys/types.h>

int main(){
int seed;
struct timeval tm;
gettimeofday( &tm, NULL );
printf( &quot;%d.%6d\n&quot;, tm.tv_sec, tm.tv_usec );
}


Feel free to modify and make suggestions to improve, I don't in particular like the 10 digit seconds, 2 would have been fine. IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
thx Chris :) I'll tuck that away until I need it Mike
________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Curious,

To limit to 2 decimal places, can't you just do this?
Code:
printf( &quot;%2d.%6d\n&quot;, tm.tv_sec, tm.tv_usec );
Notice the 2 by the first %d? It has been years since I did C, but I think that is all you need.

If I'm wrong, go ahead and correct me. Einstein47
(&quot;For every expert, there is an equal and opposite expert.&quot; - Arthur C. Clarke)
 
Einstein47, thanks for the reply.

I have tried that, it didn't work for me. From the man pages for printf it seems that bit defines the minimum length of the field, not the maximum length.
But if there is a way around it I would really like to know, like I said, my C is basically non-existent.

Regards
Chris IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 

the correct syntax is:

printf(&quot;%02.6d %02.6d\n&quot;,tm.tv_sec, tm.tv_usec );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top