转换为/从DateTime和C ++ 11中的字符串 [英] Convert to/from DateTime and string in C++ 11

查看:226
本文介绍了转换为/从DateTime和C ++ 11中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取当前的DateTime

将其转换为std :: string(因为它将被传递给需要std :: string的加密函数)



然后我将加密的字符串存储在一个文件中。

以后我会读取字符串,解码它



我想将它改回DataTime



然后,我想找到刚刚检索到的DateTime之间的分钟数当前的约会时间。



我已经玩了好几年了,尝试从t'interwebs收集的各种东西,但找不到任何有意义的东西对我来说 - 很多东西'前C ++ 11'或C语言而不是C ++



我会感激一些帮助!

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!

推荐答案

有很多将日期时间转换为字符串的函数 [ ^ ],但转换回来并不容易。你可能需要自己编写。但是,除非您需要将值显示为格式化日期和格式。时间,您可以使用 cout sprintf 将其转换为简单的十进制字符串。这将使加密/解密和转换回其原始值更加容易。找到两个这样的值之间的区别是简单的数学。
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.


这篇关于转换为/从DateTime和C ++ 11中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆