user1283776
user1283776

Reputation: 21764

How to create a fixed QDateTime from a string?

How can I create a fixed time for testing purposes?

I'm thinking something like:

static QDateTime startTime = "2001-02-03 14:55:02"

What would be the correct syntax?

Upvotes: 1

Views: 334

Answers (1)

hetepeperfan
hetepeperfan

Reputation: 4411

From the Qt docs: http://doc.qt.io/qt-5/qdatetime.html

static QDateTime starttime = QDateTime::fromString("2001-02-03 14:55:02");

might be what you are looking for.

A QDateTime can be parsed from a string using the static member function QDateTime::fromString() this class function, creates a QDateTime internally, intializes it from parsing the string and returning The QDateTime it created.

Upvotes: 3

Related Questions