File System view/model How to change format of date modified?
-
I have a QTreeView showing the contents of a QFileSystemModel. The last column shows the date modified for each item, but I want to change the format of this to be shorter. Right now it shows it in dd MMM YYYY HH:MM:SS i.e "31 May 2019 12:01:09" format. I want to change this to more of a "31/5/19 12:01:08" format.
-
Just do it like this then :)
dd/M/yy HH:MM:SS
should work. -
@basimchowdhury said in File System view/model How to change format of date modified?:
but how do i do this for all items in the file system?
Never used a QFileSystemModel before, but I guess you are using
QDateTime QFileSystemModel::lastModified(const QModelIndex &index) const
(wow, code as hyperlink actually works).
So when you set your data to your model, you simply convert theQDateTime
, which you recieve, to the format of your choice.You can convert
fromString
toQDateTime
and vice versa (withQDateTime::toString("dd/M/yy HH:MM:SS")
).EDIT:
I forgot about your QTreeView... Just set the TreeView-Item-Text toQDateTime::toString("dd/M/yy HH:MM:SS")
. Then it should display the right format.