Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-02-2010
Member
 
Join Date: Jan 2010
Posts: 29
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.
Reply With Quote
  #2  
Old 02-02-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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 );
Reply With Quote
  #3  
Old 02-02-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
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

Last edited by Praetor : 02-02-2010 at 08:40 PM.
Reply With Quote
  #4  
Old 02-02-2010
Member
 
Join Date: May 2008
Posts: 2,008
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
Reply With Quote
  #5  
Old 02-02-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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().
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 07:28 PM.