c++ - QDate::FromString() 问题与 QDate.year() 总是返回 -4713

标签 c++ qt terminal

我正在尝试向 QDate 对象添加日期。月份和日期被正确地放入 Qdate 对象中,但年份总是读回 -4713。

这是我的代码:

int main(int argv, char *argc[])
{
   // Show all my arguments to make sure they are correct
   qDebug() << "\n";
   for( int i = 0; i < argv ; i++)
   {
      qDebug() << i << ":  " << argc[i] << "\n";
   }

   // Add the yyyy-mm-dd date into date
   QDate date = QDate::fromString(argc[1],"yyyy-mm-dd");

   // Check to see if the date is correct
   qDebug() << "Year: " << date.year() << "\nMonth:" << date.month() << "\nDay" << date.day();
   return 0;

这是我在终端中使用的:

./birthday "1992-01-01"

输出看起来像这样:

0 : ./birthdays
1 : 1990-01-01
Year: -4713
Month: 1
Day:   1

现在无论我为我的年份选择什么,它总是返回 -4713。有谁知道为什么?我已经在这个问题上停留了一段时间,不明白这里发生了什么。

最佳答案

也许它因 Qt 版本而异,但对我来说,字符串根本没有转换,直到我制作字母 m - 大写字母 "yyyy-MM-dd" 然后它开始工作(我的版本是 5.1.0)

你可能还看到了here .提到的 M 是大写的。

关于c++ - QDate::FromString() 问题与 QDate.year() 总是返回 -4713,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21590069/

相关文章:

java - 无法找到或加载主类 osx 终端

c++ - 使函数 primitve param const 如何导致编译器优化的好例子

qt - 函数运行时如何设置标签文本?

c++ - 将类添加到基本 Qt GUI 应用程序时出现 Qt 链接器错误

c - 使用 pthread 函数的 strtol 上的段错误

linux - 如何在 openBSD 上使用 git 设置自动完成?

c++ - 进程是否在退出时自动清理 pthreads 占用的资源

C++ 头文件和源目录

c++ - 用于显示文本模式菜单的库?

c++ - Qt 中信号槽的层次结构太深