Hello!
I need to read a timestamp that contains the number of seconds since 1/1/1904 00:00:00 and print the date and time (the timestamp is a TDMS timestamp value calles wf_start_time).
I used the localtime() function from the time.h , and took down 66 years(the difference between 1904 and 1970) from the year value of the tm structure.
This works perfectly when the date is from 1970 and up. When I try a file that contains a date that is before 1/1/1970 00:00:00, I get wrong values(year and month are ok, the rest is wrong).
The timestamp also contains another value to calculate the hundredth of seconds, that is calculates by multiplying the value by 2^-64, however this one is not a problem.
This is the function I wrote:
I would appreciate any help with this kind of convertion.Code:void time_print(unsigned long long int hundredth_of_sec,signed long long int date){ struct tm start_time; double hundredth_calc=(double)hundredth_of_sec*pow(2.0,-64.0);//calculates the hundredth of sec value. time_t seconds_for_calc=date; hundredth_calc=(int)(hundredth_calc*100+0.5)*10; start_time=*localtime(&seconds_for_calc); start_time.tm_year=start_time.tm_year-66; printf("wf_start_time %d/%d/%d %d:%d:%d.%.0f\n",start_time.tm_mday,(start_time.tm_mon+1),(start_time.tm_year+1900),start_time.tm_hour,start_time.tm_min,start_time.tm_sec,hundredth_calc); }
Thank you