Questions tagged [qdatetime]

A QDateTime is a class from the Qt toolkit which provides functions for working with both dates and times.

A QDateTime object is a combination of the QDate and QTime classes which contains information about a calendar date and clock time. It can read the current date and time from the system clock, and also provides functions for comparing, formatting and parsing date/times, and for performing basic date/time calculations.

The official documentation can be found here.

88 questions
20
votes
3 answers

converting QdateTime to normal python dateTime?

I have a lot of existing code that just uses the normal dateTime class in python, however in upgrading my program I am using the QtGui.QdateTimeEdit() class, but that class returns a QdateTime object that seems to be incompatible with the normal…
Scott C
  • 325
  • 1
  • 2
  • 7
11
votes
1 answer

How to force QDateTime::fromString to read UTC time

I have some input containing UTC time formatted according to iso8601. I try to parse it using QDateTime: const char* s = "2009-11-05T03:54:00"; d.setTimeSpec(Qt::UTC); d = QDateTime::fromString(s, Qt::ISODate); Qt::TimeSpec ts =…
danatel
  • 4,844
  • 11
  • 48
  • 62
10
votes
3 answers

Qt ISODate formatted date/time including timezone

Does anyone know of a cleaner way to get the time zone included in the ISO string representation of a QDateTime? I should be able to just use the following: qDebug() << QDateTime::currentDateTime().toString(Qt::ISODate); but this always comes out…
RobbieE
  • 4,280
  • 3
  • 22
  • 36
7
votes
2 answers

How to use QDateTime::fromString?

I now, the question sounds rather silly, but I just can't get it to work. Worst example: QString time_format = "yyyy-MM-dd HH:mm:ss"; QDateTime a = QDateTime::currentDateTime(); QString as = a.toString(time_format); qDebug() << as; // print…
FooTheBar
  • 818
  • 1
  • 9
  • 20
7
votes
1 answer

How can you convert QDate in PyQt5 to a datetime.date?

I am trying to convert a date gathered from a QDateEdit into datetime.date for use in a sqlite3 database. I have seen that in PyQt4 you could use toPyDateTime however it doesnt seem to be in PyQt5. If this function is completely gone is there a way…
user1921942
  • 121
  • 1
  • 2
  • 9
6
votes
2 answers

QDateTime to QString with milliseconds in Qt3

Is there a way in Qt3 to convert QDateTime into a QString and back to QDateTime, so that eventually QDateTime will contain information about milliseconds? Thanks.
nick
  • 643
  • 1
  • 5
  • 11
6
votes
2 answers

Counting days between two dates

I tried to make a program with Qt that counts how many days are between two dates. The problem is that I am novice in Qt and I haven't got it working. I guess QDateTime is easy, but I don't understand the structure of a program. Could somebody…
Sep
  • 91
  • 1
  • 1
  • 2
5
votes
1 answer

QDateTime::fromString returns invalid Date, what am I missing?

I have some code that reads a datetime from a sqlite database, the datetime is returned as a string. when I try to convert it to a date using QDateTime::FromString it returns an invalid date. Below is the time as returned from the database and…
user1127081
  • 161
  • 1
  • 3
  • 13
5
votes
1 answer

How do I sort a QList of QDateTime*?

How do I sort a QList of QDateTime* objects by the value of the QDateTime object?
Jon
  • 3,985
  • 7
  • 48
  • 80
4
votes
1 answer

QDateEdit.date().toString("MMMM dd, yyyy") does not display months in English

I have a QDateEdit which is called date. No matter what I do, I'm not able to make it display the months in English, it always displays them in my current locale. I've already tried: self.ui.date.setLocale(QtCore.QLocale( QtCore.QLocale.English,…
Eduardo
  • 631
  • 1
  • 12
  • 25
4
votes
2 answers

How to find out the UTC offset of my current location in Qt 5.1?

I had to write a function returning the offset from UTC of my current location. To my greatest surprize, the following code returned 0: const QDateTime now = QDateTime::currentDateTime(); return now.toUTC().secsTo(now) / 60;
mBardos
  • 2,872
  • 1
  • 19
  • 16
3
votes
2 answers

Preferred way to handle UTC/local time in Qt's QDateTime?

I have some code where I write a QDateTime to a file... someQDateTime.toUTC().toString(Qt::ISODate) and when I read it back using QDateTime::fromString(), I get the time interpreted as being in the system's time zone. I can manually append "Z" to…
Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
3
votes
2 answers

Qt 5.2.1: cannot parse date/time

I am having a problem in parsing a date from QString using Qt 5.2.1... I am using the following code: QString value = "1979-10-27T04:00:00.000"; QDateTime dt = QDateTime::fromString(value, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'zzz"); but the returned…
Morix Dev
  • 2,700
  • 1
  • 28
  • 49
3
votes
1 answer

QMediaplayer duration is wrong

I'm developing a video player using Qmediaplayer. when I set a label to show duration of a video it display wrong value. float duration = mediaPlayer.duration() /…
Madusha
  • 131
  • 2
  • 3
  • 13
3
votes
1 answer

Use QFileInfo to find creation date and time

Here's the code I have right now /* Rename existing project files to .old */ if (FileIOUtil::fileExists(dest, outFileName)) { QFile oldFile(outFileName); QFileInfo fileInfo; fileInfo.setFile(oldFile); QDateTime created =…
Arnab Datta
  • 5,356
  • 10
  • 41
  • 67
1
2 3 4 5 6