如何使用CString格式化CTime声明的日期和时间? [英] How to format the date and time which was declared by CTime using CString?

查看:242
本文介绍了如何使用CString格式化CTime声明的日期和时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将系统时间记录到我的应用程序日志文件中,但是我无法对其进行格式化,而且我不知道CTime数据类型的正确格式说明符.我只是使用了%c"格式说明符,因此产生了一些垃圾.


I have to log the system time to my app log file but I am not able to format it and I dont know the proper format specifier for CTime datatype. I just used "%c" format specifier it gives some junk as result.


CString str;

m_testTime = CTime::GetCurrentTime();

str.Format(_T("%c"),m_testTime);   // not working fine
LOG(LOG_DEBUG, _T("\nSystem time :") + str);

m_nRunNumber = 10;                      //Below part working fine
str.Format(_T("%d"), mvData.m_nRunNumber);
LOG(LOG_DEBUG, _T("\nRun number: ") + str);



请对此提供帮助

[edit]添加了代码块-OriginalGriff [/edit]



Pls help with this

[edit]Code block added - OriginalGriff[/edit]

推荐答案

看看此
Have a look at this link[^]. Has a lot of different format parameters. :)


这里有一篇文章应该对您有所帮助:格式化日期和时间根据每个用户的语言环境设置 [^ ]
我认为您可能正在寻找%x" ...
There is an article which should help here: Format Date and Time As Per User''s Locale Settings[^]
I think "%x" is probably what you are looking for...


这篇关于如何使用CString格式化CTime声明的日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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