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. How to add days,hours and minutes to QDataTime
Forum Updated to NodeBB v4.3 + New Features

How to add days,hours and minutes to QDataTime

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 6.1k 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.
  • M Offline
    M Offline
    mark_ua_1999
    wrote on 18 Nov 2017, 21:00 last edited by mark_ua_1999
    #1

    Hi I am trying to change my data adding 2 days and 300 seconds but my code dont work do you have any ideas how to resolve it thanks.
    QString format = "yyyy-MM-dd HH:mm";
    QDateTime a1 = QDateTime::fromString("2017-11-19 12:49", format);//час в дорозі

     a1.addDays(2);
     a1.addSecs(300);
    // a2.addSecs(time[time.size()-i].toInt()+500);
     QString s = a1.toString(format);
    // QString s1 = a2.toString(format);
     ui->textBrowser->append(s);```
    

    //your code here

    J 1 Reply Last reply 18 Nov 2017, 21:06
    0
    • M mark_ua_1999
      18 Nov 2017, 21:00

      Hi I am trying to change my data adding 2 days and 300 seconds but my code dont work do you have any ideas how to resolve it thanks.
      QString format = "yyyy-MM-dd HH:mm";
      QDateTime a1 = QDateTime::fromString("2017-11-19 12:49", format);//час в дорозі

       a1.addDays(2);
       a1.addSecs(300);
      // a2.addSecs(time[time.size()-i].toInt()+500);
       QString s = a1.toString(format);
      // QString s1 = a2.toString(format);
       ui->textBrowser->append(s);```
      

      //your code here

      J Online
      J Online
      JonB
      wrote on 18 Nov 2017, 21:06 last edited by
      #2

      @mark_ua_1999

       a1.addDays(2);
       a1.addSecs(300);
      

      Look at the documentation. These are functions returning a new QDateTime, they do not change the a1 value.

       a1 = a1.addDays(2);
       a1 = a1.addSecs(300);
      
      M 1 Reply Last reply 18 Nov 2017, 21:20
      4
      • J JonB
        18 Nov 2017, 21:06

        @mark_ua_1999

         a1.addDays(2);
         a1.addSecs(300);
        

        Look at the documentation. These are functions returning a new QDateTime, they do not change the a1 value.

         a1 = a1.addDays(2);
         a1 = a1.addSecs(300);
        
        M Offline
        M Offline
        mark_ua_1999
        wrote on 18 Nov 2017, 21:20 last edited by
        #3

        @JNBarchan thanks for your help

        1 Reply Last reply
        0

        1/3

        18 Nov 2017, 21:00

        • Login

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