Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Round time to hour
Qt 6.11 is out! See what's new in the release blog

Round time to hour

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 636 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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by Damian7546
    #1

    Hi,
    I have time in textField like below:

    tf6.text = new Date(elapsed).toLocaleTimeString(Qt.locale(), "hh" + ":" + "mm")

    When in this text field I have time > 2:15, I would liketo get integer 3.. How to this ?

    JonBJ 1 Reply Last reply
    0
    • D Damian7546

      Hi,
      I have time in textField like below:

      tf6.text = new Date(elapsed).toLocaleTimeString(Qt.locale(), "hh" + ":" + "mm")

      When in this text field I have time > 2:15, I would liketo get integer 3.. How to this ?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Damian7546
      Do the rounding on the Date JS Date Object not on the string produced from it.

      1 Reply Last reply
      1
      • RusticusR Offline
        RusticusR Offline
        Rusticus
        wrote on last edited by
        #3

        You can check if the minutes are bigger than X and just set hour and minutes

        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date?retiredLocale=de

        hour = date.getHours()
        minute = date.getMinutes()
        
        if(minute > 0){
          date.setMinutes(0)
          date.setHours(hour+1)
        }
        
        
        1 Reply Last reply
        2

        • Login

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