1825770 Members
2002 Online
109687 Solutions
New Discussion

how to use fime( )

 
SOLVED
Go to solution
KO kwang tae
Advisor

how to use fime( )

i would like to use ftime() function.

but , i don't know how to use..

do i make C program?

please help me...
4 REPLIES 4
Sanjay Kumar Suri
Honored Contributor

Re: how to use fime( )

Seems so as the man pages says:

ftime() fills in a structure pointed to by its argument, as defined by :

/*
* Structure returned by ftime system call
*/
struct timeb {
time_t time;
unsigned short millitm;
short timezone;
short dstflag;
};

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Sridhar Bhaskarla
Honored Contributor
Solution

Re: how to use fime( )

Hi,

Below is a simple program to give you number of seconds since January 1st , 1970

#include
main()
{
struct timeb mytime;
ftime(&mytime);
printf ("time in seconds since epoch is %d\n", mytime.time);
}

Look at the man page of ftime to get more information. There are three other members in this structure that you can use.

Remember time() is to be used instead of ftime() as it is for backward compatibility for older systems.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: how to use fime( )

Time() returns the number of seconds since Jan 1, 1970 00:00:00 UTC often called epoch seconds. A more useful function for most purposes is localtime which uses the epoch seconds as an argument. Easier than using C is to use Perl:

#!/usr/bin/perl -w

my $seconds = time();
printf ("Epoch Seconds = %d\n",$seconds);
my($sec,$min,$hour,$mon,$year,$wday,$yday,$isdst) = localtime($seconds);

$year += 1900;
$mon += 1;

printf("Sec: %d Min: %d Hr: %d Month: %d\n",
$sec,$min,$hour,$mon);
printf("Yr: %d Wk Day: %d Yr Day: %d Is Dst? %d\n",
$year,$wday,$yday,$isdst);

If it ain't broke, I can fix that.
KO kwang tae
Advisor

Re: how to use fime( )

could you tell me how to compile PERL?

thanks in advance!