I have a datetime string with microsecond. I use the following script to get a QDateTime
object and add it to a memory layer:
layer = QgsVectorLayer("Point?crs=EPSG:4326", "test", "memory")
layer.dataProvider().addAttributes([QgsField("dt", QVariant.DateTime)])
layer.updateFields()
QgsProject.instance().addMapLayer(layer, True)
s = "22/04/20 05:14:38:560000" # 560000 microsec = 560 millisec
# PyQt5 doesn't support microsec, so s[:-3]
dt = QDateTime.fromString(s[:-3], "yy/MM/dd HH:mm:ss:zzz").addYears(100)
feat = QgsFeature(layer.fields())
feat.setGeometry(QgsGeometry()) # empty geometry for test
feat["dt"] = dt
layer.dataProvider().addFeatures([feat])
layer.updateExtents()
But the millisecond part is missing in the attribute table.
How can I display the millisecond part in attribute table?
I do calculation at the level of milliseconds.