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
Qt 6.11 is out! See what's new in the release blog

Qtime

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 1.3k Views 2 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.
  • S Offline
    S Offline
    satyanarayana143
    wrote on last edited by
    #1

    how to display time with nanoseconds

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

      Hi,

      You can mix qDebug and std::chrono duration.

      You should give more information about want you want to do.

      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
      • S Offline
        S Offline
        satyanarayana143
        wrote on last edited by
        #3

        i tried but not coming exactly give some code

        1 Reply Last reply
        0
        • S Offline
          S Offline
          satyanarayana143
          wrote on last edited by
          #4

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include <chrono>
          #include <iomanip>
          #include <iostream>

          std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
          auto duration = now.time_since_epoch();
          typedef std::chrono::duration<int, std::ratio_multiply<std::chrono::hours::period, std::ratio<1>
                  >::type> Days; /* UTC: +8:00 */
          
          Days days = std::chrono::duration_cast<Days>(duration);
          duration -= days;
          auto hours = std::chrono::duration_cast<std::chrono::hours>(duration);
          duration -= hours;
          auto minutes = std::chrono::duration_cast<std::chrono::minutes>(duration);
          duration -= minutes;
          auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration);
          duration -= seconds;
          auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
          duration -= milliseconds;
          auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(duration);
          duration -= microseconds;
          auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
          std::cout << hours.count() << ":"<< minutes.count() << ":"<< seconds.count() << ":"
                << milliseconds.count() << ":" << microseconds.count() << ":" << nanoseconds.count() << std::endl;
          
          
          auto now1 = std::chrono::high_resolution_clock::now();
          auto time = std::chrono::system_clock::to_time_t(now1);
          auto tm = *std::gmtime(&time);
          auto epoch = now1.time_since_epoch();
          auto us = std::chrono::duration_cast<std::chrono::microseconds>(epoch).count() % 1000000;
          std::cout << std::put_time(&tm, "%F %T.") << us; //<< std::put_time(&tm, " %Z\n");
          

          this is my code where i am doing wrong

          //     QDateTime myDateTime = QDateTime::fromMSecsSinceEpoch(ns / 1000000);
          

          // const qlonglong nanosecs = 5555555;

          // QDateTime myDateTime = QDateTime::fromMSecsSinceEpoch(nanosecs / 1000000);

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Still no idea what you want to achieve and what you think what is not working.
            QDateTime can not handle nanoseconds.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • S Offline
              S Offline
              satyanarayana143
              wrote on last edited by
              #6

              @satyanarayana143 said in Qtime:

              how to display time with nanoseconds

              i want to display time with nanoseconds

              Christian EhrlicherC 1 Reply Last reply
              0
              • S satyanarayana143

                @satyanarayana143 said in Qtime:

                how to display time with nanoseconds

                i want to display time with nanoseconds

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by Christian Ehrlicher
                #7

                @satyanarayana143 said in Qtime:

                i want to display time with nanoseconds

                Then don't use QDateTime or handle the nanoseconds separately from QDateTime

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  satyanarayana143
                  wrote on last edited by
                  #8

                  i am not using qdatetime chrono librariy iam using

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • S satyanarayana143

                    i am not using qdatetime chrono librariy iam using

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @satyanarayana143 So why do you ask in a Qt forum then?

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      satyanarayana143
                      wrote on last edited by
                      #10

                      i want to display in qt

                      JonBJ 1 Reply Last reply
                      0
                      • S satyanarayana143

                        i want to display in qt

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

                        @satyanarayana143
                        Then make a string of it and display it in a QLabel.

                        1 Reply Last reply
                        1
                        • S Offline
                          S Offline
                          satyanarayana143
                          wrote on last edited by
                          #12

                          time not coming properly what is the mistake in code

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @satyanarayana143 said in Qtime:

                            time not coming properly

                            This is no error description and has nothing to do with Qt at all...

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            1

                            • Login

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