C++ 将 QDate 转换为 Qstring?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9726430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert QDate to Qstring?
提问by Letholdrus
I have trouble converting QDate to QString. See the code below:
我无法将 QDate 转换为 QString。请参阅下面的代码:
cout << QString("\nBooking Date: %1").arg(QDate::toString(this->getBookingDate() &YYYY.mm.dd)
When I try to compile this it gives me:
当我尝试编译它时,它给了我:
‘YYYY' was not declared in this scope
Yet the documentation says:
然而文档说:
"Returns the date as a string. The format parameter determines the format of the result string..." and goes on to list the format strings.
“以字符串形式返回日期。格式参数确定结果字符串的格式...”并继续列出格式字符串。
I am new to Qt so if I am missing the obvious please excuse the ignorance.
我是 Qt 的新手,所以如果我遗漏了明显的内容,请原谅我的无知。
回答by jpm
You want this->getBookingDate().toString("yyyy.MM.dd")
. For further info, read the documentation.
你要this->getBookingDate().toString("yyyy.MM.dd")
。有关更多信息,请阅读文档。
回答by Rajiv Sharma
in PySide2 you can use this:
在 PySide2 中你可以使用这个:
self.dateEdit.date().toString("yyyy.MM.dd")