Results 1 to 3 of 3

Thread: How can I get the date out of QFileInfo?

  1. #1
    Join Date
    Apr 2017
    Posts
    55
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How can I get the date out of QFileInfo?

    I am using the find file dialog code at https://doc.qt.io/archives/qt-4.8/qt...s-example.html

    I added the lines:
    Qt Code:
    1. QDateTime fdate = QFileInfo(file).lastModified();
    2. QString sdate = fdate.toString("mm/dd/yyyy");
    3. qDebug() << sdate;
    4.  
    5. QTableWidgetItem *fileNameItem = new QTableWidgetItem(files[i]);
    6. fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
    7. QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("")
    8. .arg(fdate.toString()));
    To copy to clipboard, switch view to plain text mode 

    QFileInfo(file).lastModified() gives the the following info:

    Wed March 18 16:15:33 2020
    Seems like kind of a jumbled way of providing a date time.

    So I want just 03/18/2020 I feed it into QString sdate = fdate.toString("mm/dd/yyyy");
    But this gives me "33/18/2020"

    First How do I get the file info lastModified to appear as 03/18/2020?

    Second I changed the declaration for sizeItem to:
    QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("")
    .arg(fdate.toString()));

    I want the date to be printed out instead of the file size. File size is useless to my needs.

    How can I accomplish that part?

    Thanks to all

    emp1953

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I get the date out of QFileInfo?

    Because 'mm' are the minutes according the documentation: https://doc.qt.io/qt-5/qdatetime.html#toString

  3. The following user says thank you to ChristianEhrlicher for this useful post:

    emp1953 (21st March 2020)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can I get the date out of QFileInfo?

    Second I changed the declaration for sizeItem to:
    QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("").arg(fdate.toString()));
    And didn't I tell you in reply to your last post (in the "General Discussion" section) how to properly format a QString().arg() expression?

    We aren't going to write your code for you, and you have to read and understand the answers so you can write it yourself.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. The following user says thank you to d_stranz for this useful post:

    emp1953 (21st March 2020)

Similar Threads

  1. Replies: 2
    Last Post: 30th August 2019, 21:16
  2. Replies: 1
    Last Post: 5th March 2014, 01:41
  3. QFileInfo
    By ishkabible in forum Qt Programming
    Replies: 3
    Last Post: 20th September 2010, 01:08
  4. Is there such a way QFileInfo
    By baray98 in forum Qt Programming
    Replies: 9
    Last Post: 21st April 2008, 04:23
  5. How to default Date-Edit Widget to system date
    By JohnToddSr in forum Qt Tools
    Replies: 4
    Last Post: 17th January 2007, 20:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.