QDateTime::fromString返回无效日期,我缺少什么
QDateTime::fromString returns invalid Date, what am I missing?
我有一些代码从sqlite数据库读取日期时间,日期时间以字符串形式返回。当我尝试使用QDateTime::FromString将其转换为日期时,它会返回一个无效的日期。以下是从数据库和转换中返回的时间。为什么解析失败?
// -this is the value returned from the DB currentServerTime=2012-01-17 19:20:27.0
QString format("yyyy/MM/dd hh:mm:ss");
QString qCurrentServerTime(currentServerTime);
now = QDateTime::fromString(qCurrentServerTime, format);
QT方面没有专家,但如果QDateTime::fromString()
如人们(合理地)预期的那样工作,并且根据这一点,您没有使用正确的模式。
如果您指示从sqllite数据库读取的字符串为"2012-01-17 19:20:27.0",那么您的格式应该为yyyy-MM-dd HH:mm:ss.z
。
详细信息:
- 您的分隔符应该是'-',而不是'/'(如示例所示)
- 时间似乎是24小时格式(19->晚上7点)(因此使用
HH
而不是hh
) - 您有一个数字表示毫秒,所以添加
.z
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 警告处理为错误这里有什么问题
- 什么时候调用组成单元对象的析构函数
- #定义c-预处理器常量..我做错了什么
- 努力将整数转换为链表。不知道我在这里做错了什么
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 什么时候在C++中返回常量引用是个好主意
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- 查询SQLite数据库中的日期
- C++避免重复声明的语法是什么
- c++库的公共头文件中应该包含什么
- C++代码的 C# 日期时间等效项是什么?
- 这种日期和时间格式是什么?
- 该代码的主要错误是什么,用于确定n`天后日期
- 在C++11中解析毫秒日期时间的最佳方法是什么
- 给定一个日期/时间作为字符串,知道当时是否是 DST 的最佳方法是什么
- 从 C/C++ 中的日期和时间转换为 UNIX 时间戳的正确方法是什么?
- QDateTime::fromString返回无效日期,我缺少什么
- 什么是最快的方式来获得日期,时间和解析成字符串以及一些其他信息
- 当为不存在的日期/时间设置CreateWaitableTimer时会发生什么?