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 = d.timeSpec();
When this fragment ends, ts
is set to localTime and d
contains 3 hours 54 minutes. Does anyone know how to read the date properly?
You want this->getBookingDate(). toString("yyyy. MM. dd") .
QDateTime::QDateTime(QDate date, QTime time, Qt::TimeSpec spec = Qt::LocalTime, int offsetSeconds = 0) Constructs a datetime with the given date and time, using the time specification defined by spec and offsetSeconds seconds. If date is valid and time is not, the time will be set to midnight.
Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, > Coordinated Universal Time (Qt::UTC). On systems that do not support time zones, this function will behave as if local time were Qt::UTC. See also setTime_t(). just tried pass string returned by QDateTime::currentDateTime().
Qt5 current date & timeQDate cd = QDate::currentDate(); The QDate::currentDate static function returns the current date. QTime ct = QTime::currentTime();
What about setting the time spec after the fromString
method.
const char* s = "2009-11-05T03:54:00";
d = QDateTime::fromString(s, Qt::ISODate);
d.setTimeSpec(Qt::UTC);
Qt::TimeSpec ts = d.timeSpec();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With