Question

I have a problem with the conversion of seconds into date. I'm reading a binary file, thus i read as "unsigned int" and it gives me seconds. Then i have to convert it to the date and print. I tried to use strftime but the last input element needs "struct tm" pointer.

I thought calculating by diversing seconds into other things such as 60 for minutes etc. But there is the fact that February may take 29 days in 4 years.

Thus, can anybodu help me for this problem? Thanks.

Was it helpful?

Solution

Assuming your seconds are seconds since 1/1/1970 you can use localtime() to convert such seconds (epoche time) to a struct tm which you can then feed to strftime().

Using localtime() takes into account the time zone settings of the machine doing the conversion.

If you are interested in GMT you can alternativly use gmtime().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top