Qtime
-
how to display time with nanoseconds
-
Hi,
You can mix qDebug and std::chrono duration.
You should give more information about want you want to do.
-
i tried but not coming exactly give some code
-
#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);
-
Still no idea what you want to achieve and what you think what is not working.
QDateTime can not handle nanoseconds. -
@satyanarayana143 said in Qtime:
how to display time with nanoseconds
i want to display time with nanoseconds
-
Christian Ehrlicher Lifetime Qt Championreplied to satyanarayana143 on last edited by Christian Ehrlicher
@satyanarayana143 said in Qtime:
i want to display time with nanoseconds
Then don't use QDateTime or handle the nanoseconds separately from QDateTime
-
i am not using qdatetime chrono librariy iam using
-
@satyanarayana143 So why do you ask in a Qt forum then?
-
i want to display in qt
-
@satyanarayana143
Then make a string of it and display it in aQLabel
. -
time not coming properly what is the mistake in code
-
@satyanarayana143 said in Qtime:
time not coming properly
This is no error description and has nothing to do with Qt at all...