Rts Programs 1st Course
Rts Programs 1st Course
Rts Programs 1st Course
<include<time.h#
-LAB -2
And before we start, we need to know that computer doesn’t
save time or date directly on memory, it used a system called
Unix time” where it depends on how many the seconds are”
passed from 1 1 1970, 00:00:00 where this date is the factory
. date for all computers
Examples
1 size_t
This is the unsigned integral type and is the result of the size
of keyword.
2 clock_t
3 time_t is
4 struct tm
/* time() example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, time() */
int main ()
{
time_t tt;
return 0;
}
: “C Time() “Convert time_t value to string
Interprets the value pointed by timer as a calendar time and
converts it to a C-string containing a human-readable version of
. the corresponding time and date, in terms of local time
.dd the day of the month, hh:mm:ss the time, and yyyy the year
/* ctime example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, time, ctime */
int main ()
{
time_t rawtime;
time (&rawtime);
printf ("The current local time is: %s", ctime (&rawtime));
return 0;
}
Lab -3-
Gmtime () function :
The gmtime() function in C++ return the time from the computer
in the UTC (Universal Time Coordinated) time. It define in ctime
library and deals with (struct tm).
int main ()
{
time_t rawtime;
struct tm * ptm;
time ( &rawtime );
return 0;
}
Example for changes the time according to the time of
: another country
/* gmtime example */
#include <stdio.h> /* puts, printf */
#include <time.h> /* time_t, struct tm, time, gmtime */
#define IND (-5)
int main ()
{
time_t rawtime;
struct tm * ptm;
time ( &rawtime );
return 0;
}
: Asctime () function
This function returns the time and date in a calendar time and
converts it to a C-string containing a human-readable version of
. the corresponding date and time
Where Www is the weekday, Mmm the month (in letters), dd the
.day of the month, hh:mm:ss the time, and yyyy the year
/*example of asctime () */
#include <stdio.h> /* puts, printf */
#include <time.h> /* time_t, struct tm, time, gmtime */
int main ()
{
time_t rawtime;
struct tm * ptm;
time ( &rawtime );
return 0;
}
int main ()
{
time_t tt;
struct tm * timeinfo;
time (&tt);
timeinfo = localtime (&tt);
return 0;
}
: Mktime() function
The mktime function is an inbuilt c++ returns the Unix time stamp
for date function which convert the local date and time to the
time science epoch and returns the value as an object of type
time _t. The function accept amendatory parameter pointer that
points to tm object structure that contains a calendar time which
.is to be converted
/*example of mktime () */
#include <stdio.h> /* printf, scanf */
#include <time.h> /* time_t, struct tm, time, mktime */
int main ()
{
time_t rawtime;
struct tm * timeinfo;
int year, month ,day;
char weekday[7][10] = { "Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
time ( &rawtime );
timeinfo = localtime ( &rawtime );
timeinfo->tm_year = year - 1900;
timeinfo->tm_mon = month - 1;
timeinfo->tm_mday = day;
mktime ( timeinfo );
return 0;
}
-Lab -6
: () clock function
The function clock() defined in the time .h header. returns the
number of clock ticks elapsed since the program was launched. To
get the number of seconds used by the CPU , you will need to
divide by CLOCKS_PER_SEC constant, which is also defined in
the time .h header returns the number of elapsed CPU clock
cycles.. On a 32 bit system where CLOCKS_PER_SEC equals
1000000 .
/*example of clock () */
#include <stdio.h>
#include <time.h>
int main () {
clock_t start, end;
float total;
int i;
start = clock();
printf("Starting of the program = %d\n", start);
return 0;}
/*example of clock () */
#include <stdio.h> /* printf */
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
#include <math.h>
return x;
}
int main ()
{
clock_t start ,end;
int f;
float t;
start = clock();
f = add (5000000);
printf ("The addition of the numbers : %d\n", f);
end=clock();
t =(float) (end-start)/CLOCKS_PER_SEC;
printf ("It took %f clicks \n", t);
return 0;
}
-Lab-5
: Difftime () function
The difftime() function is defined in ctime header file. The
difftime() function is used to calculate the difference between
two times in second. This method accepts two parameters ,
/*example of difftime () */
#include <stdio.h>
#include <time.h>
int main ()
{
time_t now;
struct tm * newyear;
int seconds;
time(&now);
newyear = localtime(&now);
newyear->tm_hour = 0;
newyear->tm_min = 0;
newyear->tm_sec = 0;
newyear->tm_mon = 0;
newyear->tm_mday = 1;
seconds = difftime(now,mktime(newyear));
return 0;
}