• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Convert unix timestamp to readable date c++

Steelerz37

Senior member
I am writing a program for a class and we need to use the stat() function to get file statistics. How can I convert the unix timestamp into a date string? I've found examples using php and c# using already built functions, are there similar functions in c++?
 
Use localtime() or gmtime() to convert it to a struct tm then use strftime() or asctime() to format it into theappropriate time string
 
Glad to help.

I used to have something like the following on my whiteboard to help me remember the various time/date transformations:

[ascii date-time string] -> strptime() -> [struct tm object] -> mktime() -> [unix timestamp] -> gmtime() -> [struct tm object] -> strftime() -> [ascii date-time string]
 
Back
Top