TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Use of mktime() : C (http://forums.techarena.in/software-development/1298402.htm)

Martien 02-02-2010 08:09 PM

Use of mktime() : C
 
Hello, I am the student of the MCA second year. I had learn the C language in the BscIT. I know about some of the header files of the C language. So, I want to know about the mktime() function. I also want to know about the what is actual use of the mktime() function, How mktime() function works, and How can I implement the mktime() function in the C language. If anyone has the any idea about the mktime() function, so Please reply me.

Modifier 02-02-2010 08:16 PM

Use of mktime() : C
 
Hi, The information of the local time can be converted in the structure that can be pointed to by pointer of the time into a calendar time i.e. Coordinated Universal Time, with the similar kind of encoding that is being used by the function time(), by the mktime() function. The following can be the syntax of the mktime(0 function :
#include <time.h>
tim_t mktime( struct t *tmpr );

Praetor 02-02-2010 08:22 PM

Use of mktime() : Program
 
Program :
Code:

#include <stdio.h>                                                             
#include <time.h>                                                             
char *wdy[] = { "Sunday", "Monday","Tuesday","Wednesday",                   
                "Thursday", "Friday", "Saturday" };                           
int main(void)                                                                 
{                                                                             
 tim_t t2, t4;                                                               
  struct tn *t3;                                                               
  t2 = time(NULL);                                                             
  t3 = localtime(&t2);                                                         
  t3 -> t_mdy += 40;                                                         
  t3 -> t_hr += 16;                                                         
  t4 = mktime(t3);                                                             
printf("40 days and 16 hours from now, it will be a %s \n",                 
          wday[t2 -> tm_wday]);                                               
}

The Output of the program :
Code:

40 days and 16 hours from now, it will be a Sunday

Katty 02-02-2010 08:29 PM

The mktime() : C
 
The tzset() function can be called, when you called the mktime() function. there can be one more example on the mktime() function :
Code:

#include <stdio.h>
#include <time.h>
static const char *wk_dy[] = {
    "Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday"
};
void main()
  {
    struct t nw_yr;
    nw_yr.t_yr  = 2001 - 1900;
    nw_yr.t_mn  = 0;
    nw_yr.t_mdy  = 1;
    nw_yr.t_hr  = 0;
    nw_yr.t_mn  = 0;
    nw_yr.t_sc  = 0;
    nw_yr.t_isdst = 0;
    mktime( &nw_yr );
    printf( "The next century begins on a %s\n",
        wk_dy[ nw_yr.t_wdy ] );
  }
OUTPUT :
The next century begins on a Monday


kelfro 02-02-2010 08:38 PM

Use of mktime()
 
Hi, According to my knowledge about the mktime() function, The incomplete time form can be converted into the completely defined format that can be pointed to by the time pointer with the value that can be normalized and converts that time into the calender time. Thus, that converted time can contain the similar encoding as that value can be returned by the time().


All times are GMT +5.5. The time now is 02:00 PM.