Thanks Richard for the update
I tried to do the folowing coding but am Getting Bus Error
Can You send me the code with actual syntax
as i am not vey good with structures and pointers
see my code below if you can find some error
Thanks & Regards
Sumeet
#include <stdio.h>
#include <time.h>
int main()
{
int
tm_sec1,tm_min1,tm_hour1,tm_mday1,tm_mon1,tm_year1 ,tm_wday1,tm_yday1,tm_isdst1;
int sec1,min1,hour1,day1,month1,year1;
char timestr[40];
char tstring[40];
struct tm *tmp,*tmp2,*tmp3;
time_t t,t2,t3;
// code to see the actual values in a time structure works fine
t = time(NULL);
tmp = localtime(&t); /* or gmtime, if you want GMT^H^H^HUTC */
tm_sec1=(tmp->tm_sec);
tm_min1=(tmp->tm_min);
tm_hour1=(tmp->tm_hour);
tm_mday1=(tmp->tm_mday);
tm_mon1=(tmp->tm_mon);
tm_year1=(tmp->tm_year);
tm_wday1=(tmp->tm_wday);
tm_yday1=(tmp->tm_yday);
tm_isdst1=(tmp->tm_isdst);
printf("value of tm_sec1 is %d\n",tm_sec1);
printf("value of tm_min1 is %d\n",tm_min1);
printf("value of tm_hour1 is %d\n",tm_hour1);
printf("value of tm_mday1 is %d\n",tm_mday1);
printf("value of tm_mon1 is %d\n",tm_mon1);
printf("value of tm_year1 is %d\n",tm_year1);
printf("value of tm_wday1 is %d\n",tm_wday1);
printf("value of tm_yday1 is %d\n",tm_yday1);
printf("value of tm_isdst1 is %d\n",tm_isdst1);
// code to see the addition of time in seconds
// giving bus error dont know how to debug
tmp2->tm_sec=20+3037734;
tmp2->tm_min=20;
tmp2->tm_hour=10;
tmp2->tm_mday=5;
tmp2->tm_mon=5;
tmp2->tm_year=106;
//tmp2->tm_wday=0;
//tmp2->tm_yday=0;
//tmp2->tm_isdst=-1;
t3=mktime(tmp2);
tmp3 = localtime(&t3); /* or gmtime, if you want GMT^H^H^HUTC */
tm_sec1=(tmp3->tm_sec);
tm_min1=(tmp3->tm_min);
tm_hour1=(tmp3->tm_hour);
tm_mday1=(tmp3->tm_mday);
tm_mon1=(tmp3->tm_mon);
tm_year1=(tmp3->tm_year);
tm_wday1=(tmp3->tm_wday);
tm_yday1=(tmp3->tm_yday);
tm_isdst1=(tmp3->tm_isdst);
printf("value of tm_sec1 is %d\n",tm_sec1);
printf("value of tm_min1 is %d\n",tm_min1);
printf("value of tm_hour1 is %d\n",tm_hour1);
printf("value of tm_mday1 is %d\n",tm_mday1);
printf("value of tm_mon1 is %d\n",tm_mon1);
printf("value of tm_year1 is %d\n",tm_year1);
printf("value of tm_wday1 is %d\n",tm_wday1);
printf("value of tm_yday1 is %d\n",tm_yday1);
printf("value of tm_isdst1 is %d\n",tm_isdst1);
return 0;
}
Richard Heathfield wrote:[color=blue]
> Summu82 said:
>[color=green]
> > HI I have to convert a time in the format
> >
> > i have
> > year
> > month
> > day
> > hour
> > min and seconds
> >
> > I need to convert this into time in seconds since 1 jan 1970 i.e the
> > epoch time[/color]
>
> Actually, you probably don't need to do this, and it's just as well, since C
> doesn't guarantee that 1/1/1970 is the epoch. Nor does it guarantee a
> resolution in seconds (but see below).
>[color=green]
> > do some modifications i.e add some time in seconds and then bring back
> > to the origi8nal format i.e year month day and hour min seconds[/color]
>
> Pick up your K&R (2nd edition) and turn to p255.
>
> Instantiate a struct tm object like this:
>
> struct tm foo = {0};
>
> to ensure that any unused objects are properly initialised. [F/X - nurses
> bite wound.]
>
> Now populate as many of the fields of the struct tm as you can, and
> particularly tm_sec and tm_min (0-59), tm_hour (0-23), tm_mday (1-31),
> tm_mon (0-11 - it's an offset from January), and tm_year (years since 1900,
> so if you mean 2006, you put 106 here).
>
> That's all you /have/ to fill in.
>
> Now add your time-in-seconds to tm_sec. Yes, I know - this will give you a
> ludicrous value. It doesn't matter.
>
> Now do this:
>
> mktime(&foo);
>
> and check out foo's fields - you will discover that everything is all
> magically sorted out for you. Isn't C marvellous?
>
> --
> Richard Heathfield
> "Usenet is a strange place" - dmr 29/7/1999
>
http://www.cpax.org.uk
> email: rjh at above domain (but drop the www, obviously)[/color]