Jump to content
  • Advertisement
Sign in to follow this  
Domarius

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

This topic is 4189 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
On windows?

eg:
SYSTEMTIME st;
GetSystemTime(&st);

Struct is documented here.
http://msdn2.microsoft.com/en-us/library/ms724950.aspx

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!