Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to get the current DateTime
Convert it to a std::string (because it is going to be passed to an encryption function that requires a std::string)

I am then going to store the encrypted string in a file.
later I will read the string, decode it

And I want to change it back into a DataTime

Then, I want to find the number of minutes between the DateTime just retrieved and the current date time.

I've been flonking around for ages, trying all sorts of stuff gleaned from t'interwebs, but can't find anything that makes sense to me - and lots of stuff 'pre-C++11' or for C rather than for C++

I'd appreciate some help!
Posted

1 solution

There are plenty of functions to convert datetime to string[^], but converting back is less easy. You may need to write your own. However unless you need to display the value as a formatted Date & Time, you could just convert it to a simple decimal string, using cout or sprintf. That would make it much easier to encrypt/decrypt, and convert back to its original value. And finding the difference between two such values is simple maths.
 
Share this answer
 
v2
Comments
_Maxxx_ 18-May-14 5:47am    
Thanks.
I forgot to mention that this is for a cross platform mobile device application - so standard C++ functions- I think the link you gave was for Windows?
Shirley, in all the years C++ has been about, there is a 'known' method of converting dates to strings and vice versa? When I write an app and someone types in a date, does everyone roll their own?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900