Saturday, 8 February 2014

Time related functions in c


            Time related functions

      Prev                                                                                              Next

      Time functions in C are used to interact with system time routine and formatted time outputs are displayed. Example programs for the time functions are given below.
……
S.no
Function
Description
1 setdate() This function used to modify the system date
2 getdate() This function is used to get the CPU time
3 clock() This function is used to get current system time
4 time() This function is used to get current system time as structure
5 difftime() This function is used to get the difference between two given times
6 strftime() This function is used to modify the actual time format
7 mktime() This function interprets tm structure as calendar time
8 localtime() This function shares the tm structure that contains date and time informations
9 gmtime() This function shares the tm structure that contains date and time informations
10 ctime() This function is used to return string that contains date and time informations
11 asctime() Tm structure contents are interpreted by this function as calendar time. This time is converted into string.

Example program for setdate() function in C:

This function is used to modify the system date.

Output:

Enter new date in the format(day month year)
01 12 2012
Now, current system date is 01-12-2012

Example program for getdate() function in C:

This function is used to get the CPU time.

Output:

Operating system’s current date is 12-01-2012

 Example program for clock() function in C:

This function is used to get current system time

 Output:

CPU start time is : 0 CPU end time is  : 380000

Example program for time() function in C:

This function is used to get current system time as structure

Output:

Number of hours since 1970 Jan 1st is 374528

Example program for difftime() function in C:

This function is used to get the difference between two given times

Output:

for loop used 15.000000 seconds to complete the execution

Example program for strftime(), asctime() and localtime() in C:

    • strftime()    - This function is used to modify the actual time format.
    • asctime()   – tm structure contents are interpreted by asctime() function as calendar time. This time is converted into string.
    • localtime() – This function shares the tm structure that contains date and time informations.

Output:

Sat Sep 22 01:15:03 2012
Today is Saturday, Sep 22.
Time is 01:15 AM.

Example program for mktime() and ctime() functions in C:

    • mktime() function interprets tm structure as calendar time.
    • ctime() function is used to return string that contains date and time informations.

Output:

 Mon Feb 4 02:30:38 2008

Example program for gmtime() function in C:

This function shares the tm structure that contains date and time informations.

 Output:

 Universal Time is Sat Sep 22 08:11:40 2012

      Prev                                                                                              Next

.


No comments:

Post a Comment