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?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 654 Views 1 Watching
  • 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 15 Jul 2019, 12:51 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.

    P 1 Reply Last reply 15 Jul 2019, 13:03
    0
    • B basimchowdhury
      15 Jul 2019, 12:51

      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.

      P Offline
      P Offline
      Pl45m4
      wrote on 15 Jul 2019, 13:03 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 15 Jul 2019, 13:35
      1
      • P Pl45m4
        15 Jul 2019, 13:03

        @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 15 Jul 2019, 13:35 last edited by
        #3

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

        P 1 Reply Last reply 15 Jul 2019, 13:48
        0
        • B basimchowdhury
          15 Jul 2019, 13:35

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

          P Offline
          P Offline
          Pl45m4
          wrote on 15 Jul 2019, 13:48 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

          1/4

          15 Jul 2019, 12:51

          • Login

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