Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current TimeStamp?

Tags:

timestamp

qt

I'm trying to get the current time as TimeStamp without success.

I have this code:

QDateTime setTime = QDateTime::fromString (QString("1970-07-18T14:15:09"), Qt::ISODate); QDateTime current = QDateTime::currentDateTime(); uint msecs = setTime.time().msecsTo(current.time());  return  QString::number(msecs); 

The output is

Sunday, January 25th 1970, 03:17:35 (GMT) 
like image 781
user63898 Avatar asked May 06 '10 12:05

user63898


People also ask

How do I get the current date timestamp?

Get Current Timestamp Using the toInstant() Method in Java If we have a date object representing the timestamp, we can also use the toInstant() method of the Date class to get the current timestamp.

What is current timestamp?

The CURRENT TIMESTAMP (or CURRENT_TIMESTAMP) special register specifies a timestamp that is based on a reading of the time-of-day clock when the SQL statement is executed at the application server.

How do you get a timestamp in Java?

Java Code:Timestamp ts = new Timestamp(date. getTime()); Above example command will return the current timestamp and save values in ts object variable.


2 Answers

In Qt 4.7, there is the QDateTime::currentMSecsSinceEpoch() static function, which does exactly what you need, without any intermediary steps. Hence I'd recommend that for projects using Qt 4.7 or newer.

like image 149
Wim Leers Avatar answered Sep 29 '22 17:09

Wim Leers


I think you are looking for this function:

http://doc.qt.io/qt-5/qdatetime.html#toTime_t

uint QDateTime::toTime_t () const

Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, > Coordinated Universal Time (Qt::UTC).

On systems that do not support time zones, this function will behave as if local time were Qt::UTC.

See also setTime_t().

like image 24
VestniK Avatar answered Sep 29 '22 15:09

VestniK