14 QDate d1(1995, 5, 17);
15 QDate d2(1995, 5, 20);
23 QDate date = QDate::fromString(
"1MM12car2003",
"d'MM'MMcaryyyy");
30 QDate date = QDate::fromString(
"130",
"Md");
36 QDate::fromString(
"1.30",
"M.d");
37 QDate::fromString(
"20000110",
"yyyyMMdd");
38 QDate::fromString(
"20000110",
"yyyyMd");
44 QDate::isValid(2002, 5, 17);
45 QDate::isValid(2002, 2, 30);
46 QDate::isValid(2004, 2, 29);
47 QDate::isValid(2000, 2, 29);
48 QDate::isValid(2006, 2, 29);
49 QDate::isValid(2100, 2, 29);
50 QDate::isValid(1202, 6, 6);
60 t = n.addSecs(10 * 60 * 60 + 5);
61 t = n.addSecs(-15 * 60 * 60);
67 QTime time = QTime::fromString(
"1mm12car00",
"m'mm'hcarss");
74 QTime time = QTime::fromString(
"00:710",
"hh:ms");
80 QTime time = QTime::fromString(
"1.30",
"m.s");
87 QTime::isValid(21, 10, 30);
88 QTime::isValid(22, 5, 62);
94 QDateTime now = QDateTime::currentDateTime();
95 QDateTime xmas(QDate(now.date().year(), 12, 25).startOfDay());
96 qDebug(
"There are %d seconds to Christmas", now.secsTo(xmas));
102 QTime time1 = QTime::fromString(
"131",
"HHh");
104 QTime time2 = QTime::fromString(
"1apA",
"1amAM");
107 QDateTime dateTime2 = QDateTime::fromString(
"M1d1y9800:01:02",
108 "'M'M'd'd'y'yyhh:mm:ss");
115 QDateTime dateTime = QDateTime::fromString(
"130",
"Mm");
121 QDateTime dateTime = QDateTime::fromString(
"1.30.1",
"M.d.s");
123 dateTime = QDateTime::fromString(
"12",
"yy");
130 QDateTime startDate(QDate(2012, 7, 6), QTime(8, 30, 0));
131 QDateTime endDate(QDate(2012, 7, 7), QTime(16, 30, 0));
132 qDebug() <<
"Days from startDate to endDate: " << startDate.daysTo(endDate);
134 startDate = QDateTime(QDate(2012, 7, 6), QTime(23, 55, 0));
135 endDate = QDateTime(QDate(2012, 7, 7), QTime(0, 5, 0));
136 qDebug() <<
"Days from startDate to endDate: " << startDate.daysTo(endDate);
138 qSwap(startDate, endDate);
139 qDebug() <<
"Days from startDate to endDate: " << startDate.daysTo(endDate);
143#if QT_DEPRECATED_SINCE(6
, 9
)
146 QDateTime local(QDateTime::currentDateTime());
147 QDateTime UTC(local.toTimeSpec(Qt::UTC));
148 qDebug() <<
"Local time is:" << local;
149 qDebug() <<
"UTC time is:" << UTC;
150 qDebug() <<
"No difference between times:" << local.secsTo(UTC);
157 QDateTime UTC(QDateTime::currentDateTimeUtc());
158 QDateTime local(UTC.toLocalTime());
159 qDebug() <<
"UTC time is:" << UTC;
160 qDebug() <<
"Local time is:" << local;
161 qDebug() <<
"No difference between times:" << UTC.secsTo(local);
167 QDateTime local(QDateTime::currentDateTime());
168 QDateTime UTC(local.toUTC());
169 qDebug() <<
"Local time is:" << local;
170 qDebug() <<
"UTC time is:" << UTC;
171 qDebug() <<
"No difference between times:" << local.secsTo(UTC);
175#if QT_DEPRECATED_SINCE(6
, 9
)
178 QDateTime local(QDateTime::currentDateTime());
179 qDebug() <<
"Local time is:" << local;
181 QDateTime UTC(local);
182 UTC.setTimeSpec(Qt::UTC);
183 qDebug() <<
"UTC time is:" << UTC;
185 qDebug() <<
"There are" << local.secsTo(UTC) <<
"seconds difference between the datetimes.";
190#if defined(__cpp_lib_crono) && __cpp_lib_crono > 201907L
192 using namespace std::chrono;
196 QDate date = std::chrono::year_month_day(std::chrono::year(2012),
197 std::chrono::month(4),
198 std::chrono::day(23));
201 QDate dateWithLiterals1 = 23d / April / 2012y;
202 QDate dateWithLiterals2 = 2012y / April / 23;
205 QDate lastDayFeb2020 = 2000y / February / last;
208 QDate firstMonday = 2020y / January / Monday[0];
211 QDate lastMonday = 2020y / January / Monday[last];
218 QDateTime local(QDateTime::currentDateTime());
219 QDateTime UTC(local.toTimeZone(QTimeZone::UTC));
220 qDebug() <<
"Local time is:" << local;
221 qDebug() <<
"UTC time is:" << UTC;
222 qDebug() <<
"No difference between times represented:" << local.secsTo(UTC);