Hi all,
I'm writing a function which extracts the day, month and year value from a pre-defined timestamp format passed by the caller. This format is: NDDD
where N is the decade number after 2000 and DDD is the day of the year. so if the timestamp is: 1001. the year would be: 2001, month would be: January and day would 1 (corresponding to 1 Jan 2001).
I've written this code for this:
But this is giving me this result:Code:int main( int argc, char **argv ) { long julian_day_num = 1001; int year_val = 0; int decade_indicator = 0; time_t time_epoch = 0; struct tm tm_stru; memset( &tm_stru, 0, sizeof( tm_stru ) ); errno = 0; decade_indicator = ( julian_day_num / 1000 ); year_val = 2000 + decade_indicator; tm_stru.tm_year = year_val - 1900; tm_stru.tm_yday = julian_day_num - ( decade_indicator * 1000 ); printf( "initial tm_yday is : %d\n", tm_stru.tm_yday ); time_epoch = mktime( &tm_stru ); printf( "year_val is : %d\n", year_val ); printf( "decade_indicator is : %d\n", decade_indicator ); printf( "tm_stru values after mktime() ....\n" ); printf( "tm_yday : %d\n", tm_stru.tm_yday ); printf( "tm_year : %d\n", tm_stru.tm_year ); printf( "tm_mon : %d\n", tm_stru.tm_mon ); printf( "tm_day : %d\n", tm_stru.tm_mday ); printf( "errno is: %d\n", errno ); return 0; } /* end of main() */
Which is not what I was expecting. What am I missing here???Code:initial tm_yday is : 1 year_val is : 2001 decade_indicator is : 1 tm_stru values after mktime() .... tm_yday : 365 tm_year : 100 tm_mon : 11 tm_day : 31 errno is: 0
Any help would be appreciated. Thanks.



LinkBack URL
About LinkBacks


