Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. File System view/model How to change format of date modified?

File System view/model How to change format of date modified?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 639 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    basimchowdhury
    wrote on last edited by
    #1

    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.

    Pl45m4P 1 Reply Last reply
    0
    • B basimchowdhury

      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.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @basimchowdhury

      Just do it like this then :)
      dd/M/yy HH:MM:SS should work.

      https://doc.qt.io/qt-5/qdatetime.html#toString-2


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      B 1 Reply Last reply
      1
      • Pl45m4P Pl45m4

        @basimchowdhury

        Just do it like this then :)
        dd/M/yy HH:MM:SS should work.

        https://doc.qt.io/qt-5/qdatetime.html#toString-2

        B Offline
        B Offline
        basimchowdhury
        wrote on last edited by
        #3

        @Pl45m4 but how do i do this for all items in the file system?

        Pl45m4P 1 Reply Last reply
        0
        • B basimchowdhury

          @Pl45m4 but how do i do this for all items in the file system?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @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 the QDateTime, which you recieve, to the format of your choice.

          You can convert fromString to QDateTime and vice versa (with QDateTime::toString("dd/M/yy HH:MM:SS")).

          EDIT:
          I forgot about your QTreeView... Just set the TreeView-Item-Text to QDateTime::toString("dd/M/yy HH:MM:SS"). Then it should display the right format.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved