Convert a QDateTime in UTC to local system time

前端 未结 2 1579
粉色の甜心
粉色の甜心 2021-02-13 11:40

I construct a QDateTime from a string like this:

QDateTime date = QDateTime::fromString(\"2010-10-25T10:28:58.570Z\", \"yyyy-MM-ddTHH:mm:ss.zzzZ\");
2条回答
  •  南旧
    南旧 (楼主)
    2021-02-13 12:31

    Is using QDateTime::toString() not giving you expected results ?

    Maybe you could try using a different format with QDateTime::toString(Qt::SystemLocaleLongDate) or QDateTime::toString(Qt::SystemLocaleShortDate).

    Otherwise, I would try to use QLocale::dateTimeFormat() to get the local format as a QString and then use this string as the format parameter of QDateTime::toString(), but I don't think it will change anything.

提交回复
热议问题