如何将文本日期和时间转换为ctime [英] How to convert a textual date and time into ctime

查看:283
本文介绍了如何将文本日期和时间转换为ctime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法将文本日期和时间转换为CTime。

文本日期和时间可以是:

I am looking for a way to convert a textual date and time into a CTime.
Textual date and time could be:

引用:

1999年12月27日

8:30:00

20:30:00

1996年1月25日8:30:00

1996年1月25日8:30

1 / 25/1996 8:30:00

"27 December 1999"
"8:30:00"
"20:30:00"
"January 25, 1996 8:30:00"
"8:30:00 Jan. 25, 1996"
"1/25/1996 8:30:00"





我尝试过:



我编写了以下函数,但是 ParseDateTime 总是失败。





What I have tried:

I wrote the following function, however ParseDateTime always fail.

CTime DateTimeString2CTime(CString DateTimeStr)
{
	COleDateTime t;
	if (t.ParseDateTime(DateTimeStr))
	{
		CTime result(t);
		return result;
	}
	return (CTime)NULL;
}

推荐答案

ParseDateTime 应该适用于有效的日期字符串。问题的原因可能是您的计算机上的区域设置不适合该日期格式。检查一下 - 也许用ParseDateTime的附加参数修复它。



或者是输入参数或CTime转换构造函数的另一个问题?
The call of ParseDateTime should work for valid date string. A reason for problems could be that your locale settings on your computer arent fitting to that date format. Check that - maybe fix it with additional parameter to ParseDateTime.

Or is it another problem from the input parameter or the CTime conversion constructor?

这篇关于如何将文本日期和时间转换为ctime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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