1833875 Members
1896 Online
110063 Solutions
New Discussion

Re: Precise date display

 
SOLVED
Go to solution
Paul Gold
Advisor

Precise date display

Is there any way of modifying the 'date' command to show tenths and hundredths of a second.

I have found the system calls ftime and gettimeofday but as our developer is only able to use shells cripts he would like to use the date command, format using .prec doesnt seem to give the desired results

any help appreciated

Paul Gold
CAST systems
5 REPLIES 5
John Palmer
Honored Contributor

Re: Precise date display

Not as far as I know. The C library routines that 'date' uses have a minimum granularity of one second.

Regards,

John
Andy Monks
Honored Contributor

Re: Precise date display

Paul, not according to the date man page.

Why not, write him a program that uses gettimeofday, and outputs what he wants. Then he can just call it from a shell script.
Andreas Voss
Honored Contributor

Re: Precise date display

Sorry i see no chance to get more precision with the date command.
Think you have to write a little C program for that.

Regards

Andrew
Andy Monks
Honored Contributor
Solution

Re: Precise date display

Hi Paul,

It's raw, but will work from a script and I'm sure you could clean it up a bit. I'm sure he can cope with nanoseconds :-)

#include
#include
main()
{
struct timeval timenow;
struct timezone zonenow;

gettimeofday(&timenow, &zonenow);
printf("time %s",ctime(&timenow.tv_sec));
printf("nano %dn",timenow.tv_usec);
}
Paul Gold
Advisor

Re: Precise date display

thanks everyone]

Andy youre a star

Paul Gold
CAST systems