summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlocale.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r--src/corelib/tools/qlocale.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 43d83db835..789a15dded 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -2964,14 +2964,17 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da
} else {
repeat = 1;
}
- switch (repeat) {
- case 1:
- result.append(m_data->longLongToString(time.msec()));
- break;
- case 3:
- result.append(m_data->longLongToString(time.msec(), -1, 10, 3, QLocaleData::ZeroPadded));
- break;
+
+ // note: the millisecond component is treated like the decimal part of the seconds
+ // so ms == 2 is always printed as "002", but ms == 200 can be either "2" or "200"
+ result.append(m_data->longLongToString(time.msec(), -1, 10, 3, QLocaleData::ZeroPadded));
+ if (repeat == 1) {
+ if (result.endsWith(zero()))
+ result.chop(1);
+ if (result.endsWith(zero()))
+ result.chop(1);
}
+
break;
case 't':