anyName
anyName

Reputation: 113

C - How to convert unsigned int seconds to string of date

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.

Upvotes: 2

Views: 1312

Answers (1)

alk
alk

Reputation: 70893

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().

Upvotes: 3

Related Questions