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. [SOLVED] truncating the QTime
Forum Update on Monday, May 27th 2025

[SOLVED] truncating the QTime

Scheduled Pinned Locked Moved General and Desktop
qtimetime
9 Posts 3 Posters 3.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.
  • L Offline
    L Offline
    Lorence
    wrote on last edited by Lorence
    #1

    qDebug() << iter->getTime_log()[0].time();

    Output
    QTime("08:34:40.244")

    Any way to truncate the seconds part of this time?

    I want it to be:
    QTime("08:34:40")

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      qDebug() << "QTime(\"" << iter->getTime_log()[0].time().toString("hh:mm::ss") << "\")";

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Lorence
        wrote on last edited by
        #3

        @SGaist hello, thanks for the reply
        can you explain me what is happening in that code?

        mrjjM 1 Reply Last reply
        0
        • L Lorence

          @SGaist hello, thanks for the reply
          can you explain me what is happening in that code?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Lorence
          it ask the time object (from time() ) to convert to a string (ToString) using the format
          hours:minutes:seconds.
          Since the milliseconds are not listed, they will not be there.

          http://doc.qt.io/qt-4.8/qtime.html#toString

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Lorence
            wrote on last edited by
            #5

            I see @mrjj thanks.

            cant i just convert the seconds part of the time to int?

            something like this QTime::setSecond(int);

            mrjjM 1 Reply Last reply
            0
            • L Lorence

              I see @mrjj thanks.

              cant i just convert the seconds part of the time to int?

              something like this QTime::setSecond(int);

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Lorence
              Hmm, dont the format work for you ?
              Not sure why you want to do anything to the seconds.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Lorence
                wrote on last edited by
                #7

                @mrjj
                it is working absolutely, but its like a little bit of complicated . okay thanks

                mrjjM 1 Reply Last reply
                0
                • L Lorence

                  @mrjj
                  it is working absolutely, but its like a little bit of complicated . okay thanks

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Lorence
                  well you basically just ask it to use another format.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Lorence
                    wrote on last edited by
                    #9

                    @mrjj
                    sorry, okay im now goign to SOLVED this thread thanks @SGaist @mrjj

                    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