gpt4 book ai didi

c++ - QDateTime::fromstring( __DATE__, "MMM d yyyy") 返回无效

转载 作者:太空狗 更新时间:2023-10-29 20:14:10 28 4
gpt4 key购买 nike

使用 QDateTime::fromstring() 解析 MSVC++ 预定义的 __DATE__(可能与 __TIME__ 结合)宏不返回任何内容(= 无效的 QDateTime 对象)。为什么?

最佳答案

来自 http://msdn.microsoft.com/en-us/library/b0084kay%28v=vs.80%29.aspx :

DATE The compilation date of the current source file. The dateis a string literal of the form Mmm dd yyyy. The month name Mmm is thesame as for dates generated by the library function asctime declaredin TIME.H.

dd 部分似乎填充了第 1..9 天的前导空格。

QtDateTime::fromstring()只支持

d   the day as number without a leading zero (1 to 31)
dd the day as number with a leading zero (01 to 31)

一个解决方案可能是在解析之前从 __DATE__ 字符串中删除重复的空格,例如与 QString::replace(" ", " ")并使用单个 d 解析日期。

关于c++ - QDateTime::fromstring( __DATE__, "MMM d yyyy") 返回无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17472735/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com