简单的问题:我想在文件中写入当前日期。以下是我的代码:
void fileWR::write()
{
QFile myfile("date.dat");
if (myfile.exists("date.dat"))
myfile.remove();
myfile.open(QIODevice::ReadWrite);
QDataStream out(&myfile);
out << (quint8) QDate::currentDate().day(); // OK!!
out << (quint8) QDate::currentDate().month(); // OK!!
out << (quint8) QDate::currentDate().year(); // NOT OK !!!
myfile.close();
}
当我阅读文件时,我发现一个字节代表日期(0x18 代表 24 日),一个字节代表月份(0x02 代表 2 月)和一个错误字节代表年份(0xe6 代表 2022 年)。我需要一年的最后两个数字(例如:2022 -> 22)。我能怎么做?谢谢保罗