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. QTime formatting HH:MM:SS.s
Forum Update on Monday, May 27th 2025

QTime formatting HH:MM:SS.s

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 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.
  • RichardR Offline
    RichardR Offline
    Richard
    wrote on last edited by
    #1

    Hi All,
    I am looking for a way to format QTime with 1 decimal second

    auto time = QDateTime::currentDateTimeUtc();
    QString sTime = time.toString("hh:mm:ss.zzz");
    

    this works fine, time is formatted nicely. I however assumed that hh:mm:ss.z and hh:mm:ss.zz was working too. But this give me an rather funny
    outcome with wrong milliseconds. When reading through the documentation I see that .zzz is supported but probably not .z and .zz. I recently upgraded from 5.3 to 5.8 and that may be related, not sure. So my question is, is there any way to format the time with one deicmal second and two decimal seconds?

    thanks, rich

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Actually zzz and z are supported, with the latter producing the milliseconds without leading zeroes (0 to 999). Obviously not what you need or expected. To answer you question: no, unfortunately, there is no built-in support for the format you requested. You need to come up with your own little function for that.

      RichardR 1 Reply Last reply
      1
      • ? A Former User

        Hi! Actually zzz and z are supported, with the latter producing the milliseconds without leading zeroes (0 to 999). Obviously not what you need or expected. To answer you question: no, unfortunately, there is no built-in support for the format you requested. You need to come up with your own little function for that.

        RichardR Offline
        RichardR Offline
        Richard
        wrote on last edited by
        #3

        @Wieland thanks for your answer. Yup, I read that too that .z is msec without leading 0. That is a bit of a silly one IMO.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Well, yes, maybe it's a bit silly, but at least it's consistent with the other formating options. But I agree, it would be nice to have more options, like the "variants" of z and zz you need now.

          1 Reply Last reply
          0
          • Chris HennesC Offline
            Chris HennesC Offline
            Chris Hennes
            wrote on last edited by
            #5

            That certainly seems to be a foolish consistency! The output of "ss.z" might read "10.5" which you'd reasonably expect to mean "ten and one half seconds" but in fact means "ten and five thousandths of a second". I'd be interested to know in what context that format is ever used.

            Chris Hennes, Pioneer Library System

            ? 1 Reply Last reply
            0
            • Chris HennesC Chris Hennes

              That certainly seems to be a foolish consistency! The output of "ss.z" might read "10.5" which you'd reasonably expect to mean "ten and one half seconds" but in fact means "ten and five thousandths of a second". I'd be interested to know in what context that format is ever used.

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @Chris-Hennes E.g. someone might only need the milliseconds, like in time.toString("z"). But I don't want to defend the available set of formatting options too much ;)

              Chris HennesC 1 Reply Last reply
              2
              • ? A Former User

                @Chris-Hennes E.g. someone might only need the milliseconds, like in time.toString("z"). But I don't want to defend the available set of formatting options too much ;)

                Chris HennesC Offline
                Chris HennesC Offline
                Chris Hennes
                wrote on last edited by
                #7

                @Wieland Good point -- it seems the real problem is not the consistency of Qt, but the inconsistency of humanity's time system. I think there is room in the world for both a standalone "z" and a formatting that shows tenths, hundredths, or thousandths of a second.

                Chris Hennes, Pioneer Library System

                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