C++ Store and retrieve a simple date, eg yyyy-mm-dd

Started by
3 comments, last by riku 16 years, 10 months ago
I know this should be a simple thing, but it's escaping me. First I was just wondering how you folks would store a date in a plain text file - would you store the raw format (seconds since 1970 or whatever it is) or would you store a human readable date, eg yyyy-mm-dd Secondly, what functions do I need to get the current time, and to display the date as yyyy-mm-dd? My problems acheiving these goals go like this; I see the C++ "time" returns the seconds since Jan 1970, and I can store that in my text file. But then I get compile errors trying to convert it from an int to a time_t. Well I could work that one out, but I can't find a function that will display it specifically in the yyyy-mm-dd format. Well I could probably work that out too, but seems like a lot of fiddling, so; I'm trying to use boost, it seems to have nice friendly functions for converting the dates, but I can't compile when I include the relevent headers - I need compiled libraries. The download link for the pre-compiled libraries on the boost site seems broken, and I'm trying to use bjam but although it correctly assumes mscv, it seems to fail for every item it tries to compile.

For local multiplayer retro themed games, visit Domarius Games.

Advertisement
On windows?

eg:
SYSTEMTIME st;
GetSystemTime(&st);

Struct is documented here.
http://msdn2.microsoft.com/en-us/library/ms724950.aspx
Yeah windows :) thanks I'll just try that.

For local multiplayer retro themed games, visit Domarius Games.

Yeah that'll do me, thanks. :)

I wanted to not have to read in the date and then convert it back to a date format, but I realised I don't have to go backwards for this project, I only need to get the current time and then it exists as a string from then on, wether I display it or write it to the file.

For local multiplayer retro themed games, visit Domarius Games.

Boost.date_time provides facilities for dates, times and calendars. It's cross platform, so you don't have to use any system specific functionality.

-Riku

This topic is closed to new replies.

Advertisement