在Visual Studio中将字符串转换为日期对象
Convert string to date object in Visual Studio
需要将一个字符串转换为数字或对象,该字符串以如下格式存储日期:"Apr 23 2014 12:39:17";在MS特定环境中与visual studio合作。
在C++中,是否有一个易于使用的函数可以实现这一点?
我这样做是为了比较字符串date和now()。
谢谢。
这是我为我的问题找到的解决方案。
澄清一下:日期的字符串表示需要转换成某种日期对象,这样我就可以找到两个日期之间的区别。
这适用于MSVisualStudio2010&使用microsoft类。(基本上,它在unix盒子上不起作用!)。
// Create 2 COleDateTime objects:
COleDateTime DateTime1;
COleDateTime DateTime2;
// 'Get' 2 string dates:
BSTR time1 = L"Apr 24 2014 09:20:20";
BSTR time2 = L"Apr 23 2014 12:39:17";
// Parse the string dates into the date objects (See! Its alot easier then I thought!)
DateTime1.ParseDateTime(time1);
DateTime2.ParseDateTime(time2);
// Calculate the time difference with a COleDateTimeSpan Object...
COleDateTimeSpan timeSpan = DateTime2 - DateTime1;
// Create integer with the difference in time in seconds...
CString str = timeSpan.Format(_T("%S"));
int differenceInSeconds = _tstoi(str);
希望这能帮助到别人!
相关文章:
- JNI 日期值转换问题,在C++中获取不同的长整型值
- 如何将我的每个矢量字符串转换为纪元时间日期
- 将 unix 时间戳转换为人类可读的日期
- 无法在初始化时将"日期"转换为"int"作为错误
- 使用 C++将时间戳转换为格式化的日期时间
- 将日期字符串转换为 unix 时间戳
- 如何在 C/Android NDK 中将字符串日期转换为毫秒
- 将 OLE 自动化日期 (OADate) 双精度转换为结构 tm,而不使用 VariantTime到SystemTime
- 如何将时间和日期转换为 C 或 C++ 的句子格式?
- 在 c++ 中将 ISO 日期时间转换为本地日期时间并提取时间
- 使用霍华德·欣南特的日期库将双倍转换为zoned_time
- 如何将毫秒的日期时间字符串转换为 UNIX 时间戳
- 用于在C++中将串行日期 (Excel) 转换为年-月-日的算法
- time_t提高日期转换,给出不正确的结果
- 在 CLI 中转换日期时间time_t错误处理C++是否安全
- 使用UTC来回转换日期以忽略DST但仍使用当前用户的有效区域设置是否安全
- 转换日期格式
- 转换日期.valueof原语转换为Ruby
- 可视化转换日期到字符串在COM c++
- C++:在时区之间转换日期时间以保持精度