QTime(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

πŸ’– QTime β€” clock time functions πŸ’–

Alright bestie, gather round. This is the manual page for QTime, straight out of the QTime(3qt) manual. It's giving clock girl energy and we're gonna get through all of it together, no skimming, no skipping. πŸŽ€


✨ NAME ✨

QTime β€” Clock time functions


🌸 SYNOPSIS 🌸

Okay so first things first, the reentrancy tea: all the functions in this class are reentrant when Qt is built with thread support.

</p>

^(yes that stray closing tag is literally in the original, I'm not touching it, it's part of the lore πŸ’€)

And you pull it in like this:

#include <qdatetime.h>

🫢 Public Members

  • QTime ()
  • QTime ( int h, int m, int s = 0, int ms = 0 )
  • bool isNull () const
  • bool isValid () const
  • int hour () const
  • int minute () const
  • int second () const
  • int msec () const
  • QString toString ( Qt::DateFormat f = Qt::TextDate ) const
  • QString toString ( const QString & format ) const
  • bool setHMS ( int h, int m, int s, int ms = 0 )
  • QTime addSecs ( int nsecs ) const
  • int secsTo ( const QTime & t ) const
  • QTime addMSecs ( int ms ) const
  • int msecsTo ( const QTime & t ) const
  • bool operator== ( const QTime & t ) const
  • bool operator!= ( const QTime & t ) const
  • bool operator< ( const QTime & t ) const
  • bool operator<= ( const QTime & t ) const
  • bool operator> ( const QTime & t ) const
  • bool operator>= ( const QTime & t ) const
  • void start ()
  • int restart ()
  • int elapsed () const

⭐ Static Public Members

  • QTime currentTime ()
  • QTime currentTime ( Qt::TimeSpec ts )
  • QTime fromString ( const QString & s, Qt::DateFormat f = Qt::TextDate )
  • bool isValid ( int h, int m, int s, int ms = 0 )
  • QDataStream & operator<< ( QDataStream & s, const QTime & t )
  • QDataStream & operator>> ( QDataStream & s, QTime & t )

πŸ‘‘ DESCRIPTION πŸ‘‘

The QTime class provides clock time functions. Periodt.

A QTime object holds a clock time, meaning the number of hours, minutes, seconds and milliseconds since midnight. It can read the current time straight off the system clock, and it can measure a span of elapsed time. It also hands you functions for comparing times, and for manipulating a time by adding a number of (milli)seconds. Obsessed, honestly.

QTime runs on the 24-hour clock format β€” it has no concept of AM/PM. It operates in local time; it knows nothing about time zones or daylight savings time. It's blissfully unbothered. πŸ™ˆ

A QTime object is typically created either by handing over the number of hours, minutes, seconds and milliseconds explicitly, or by calling the static function currentTime(), which builds you a QTime containing the system's clock time. Heads up though: the accuracy depends on the accuracy of the underlying operating system, and not all systems provide 1-millisecond accuracy. Lowkey important, don't @ me.

The hour(), minute(), second() and msec() functions give you access to the hours, minutes, seconds and milliseconds of the time. And the same info comes in textual format from the toString() function. Two paths, same destination, iconic. ✨

QTime brings a full set of operators to compare two QTime objects. One time counts as smaller than another if it's earlier than the other.

Want the time a given number of seconds or milliseconds later than a given time? That's addSecs() or addMSecs(). And correspondingly, the number of (milli)seconds between two times is secsTo() or msecsTo().

QTime can also measure a span of elapsed time using start(), restart() and elapsed(). ⏱️

See also QDate, QDateTime, and Time and Date.


πŸŽ€ MEMBER FUNCTION DOCUMENTATION πŸŽ€

QTime::QTime ()

Constructs the time 0 hours, minutes, seconds and milliseconds β€” aka 00:00:00.000 (midnight). And yes, this is a valid time. πŸ’…

See also isValid().

QTime::QTime ( int h, int m, int s = 0, int ms = 0 )

Constructs a time with hour h, minute m, seconds s and milliseconds ms.

So here's the vibe check on the ranges: h must be in the range 0..23, m and s must be in the range 0..59, and ms must be in the range 0..999.

See also isValid().

QTime QTime::addMSecs ( int ms ) const

Returns a QTime object containing a time ms milliseconds later than the time of this object (or earlier if ms is negative).

Note that the time will wrap if it passes midnight. For an example, go peep addSecs(). πŸ‘€

See also addSecs() and msecsTo().

QTime QTime::addSecs ( int nsecs ) const

Returns a QTime object containing a time nsecs seconds later than the time of this object (or earlier if nsecs is negative).

Note that the time will wrap if it passes midnight.

Example:

QTime n( 14, 0, 0 );                // n == 14:00:00
QTime t;
t = n.addSecs( 70 );                // t == 14:01:10
t = n.addSecs( -70 );               // t == 13:58:50
t = n.addSecs( 10*60*60 + 5 );      // t == 00:00:05
t = n.addSecs( -15*60*60 );         // t == 23:00:00

See also addMSecs(), secsTo(), and QDateTime::addSecs().

QTime QTime::currentTime ( Qt::TimeSpec ts ) [static]

Returns the current time as reported by the system clock, for the TimeSpec ts. The default TimeSpec is LocalTime.

Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

See also Qt::TimeSpec.

Examples:

^(the examples didn't survive into this man page, so we're holding a moment of silence for them 🫢)

QTime QTime::currentTime () [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the current time as reported by the system clock.

Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

int QTime::elapsed () const

Returns the number of milliseconds that have elapsed since the last time start() or restart() was called.

Note that the counter wraps to zero 24 hours after the last call to start() or restart.

Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

⚠️ Warning: If the system's clock setting has been changed since the last time start() or restart() was called, the result is undefined. This can happen when daylight savings time is turned on or off. So like, be careful bestie. 😭

See also start() and restart().

QTime QTime::fromString ( const QString & s, Qt::DateFormat f = Qt::TextDate ) [static]

Returns the representation s as a QTime using the format f, or an invalid time if this is not possible.

⚠️ Warning: Note that Qt::LocalDate cannot be used here.

int QTime::hour () const

Returns the hour part (0..23) of the time.

Examples:

^(again, the examples are a no-show in this render, rip πŸͺ¦)

bool QTime::isNull () const

Returns TRUE if the time is equal to 00:00:00.000; otherwise returns FALSE. A null time is valid, btw. Yes, valid. We love a plot twist.

See also isValid().

bool QTime::isValid () const

Returns TRUE if the time is valid; otherwise returns FALSE. For reference, 23:30:55.746 is valid, whereas 24:12:30 is invalid.

See also isNull().

bool QTime::isValid ( int h, int m, int s, int ms = 0 ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns TRUE if the specified time is valid; otherwise returns FALSE.

The time is valid if h is in the range 0..23, m and s are in the range 0..59, and ms is in the range 0..999.

Example:

QTime::isValid(21, 10, 30); // returns TRUE
QTime::isValid(22, 5,  62); // returns FALSE

int QTime::minute () const

Returns the minute part (0..59) of the time.

Examples:

^(yes. also missing. I know. πŸ’€)

int QTime::msec () const

Returns the millisecond part (0..999) of the time.

int QTime::msecsTo ( const QTime & t ) const

Returns the number of milliseconds from this time to t (which is negative if t is earlier than this time).

Because QTime measures time within a day, and there are 86400 seconds in a day, the result is always between -86400000 and 86400000 msec. Slay, bounded.

See also secsTo().

bool QTime::operator!= ( const QTime & t ) const

Returns TRUE if this time is different from t; otherwise returns FALSE.

bool QTime::operator< ( const QTime & t ) const

Returns TRUE if this time is earlier than t; otherwise returns FALSE.

bool QTime::operator<= ( const QTime & t ) const

Returns TRUE if this time is earlier than or equal to t; otherwise returns FALSE.

bool QTime::operator== ( const QTime & t ) const

Returns TRUE if this time is equal to t; otherwise returns FALSE.

bool QTime::operator> ( const QTime & t ) const

Returns TRUE if this time is later than t; otherwise returns FALSE.

bool QTime::operator>= ( const QTime & t ) const

Returns TRUE if this time is later than or equal to t; otherwise returns FALSE.

int QTime::restart ()

Sets this time to the current time and returns the number of milliseconds that have elapsed since the last time start() or restart() was called.

This function is guaranteed to be atomic, which makes it super handy for repeated measurements. Call start() to kick off the first measurement and then restart() for each later one. Main character scheduling energy. πŸ‘‘

Note that the counter wraps to zero 24 hours after the last call to start() or restart().

⚠️ Warning: If the system's clock setting has been changed since the last time start() or restart() was called, the result is undefined. This can happen when daylight savings time is turned on or off.

See also start(), elapsed(), and currentTime().

int QTime::second () const

Returns the second part (0..59) of the time.

Example: tictac/tictac.cpp.

int QTime::secsTo ( const QTime & t ) const

Returns the number of seconds from this time to t (which is negative if t is earlier than this time).

Because QTime measures time within a day, and there are 86400 seconds in a day, the result is always between -86400 and 86400.

See also addSecs() and QDateTime::secsTo().

Example: t12/cannon.cpp.

bool QTime::setHMS ( int h, int m, int s, int ms = 0 )

Sets the time to hour h, minute m, seconds s and milliseconds ms.

h must be in the range 0..23, m and s must be in the range 0..59, and ms must be in the range 0..999. Returns TRUE if the set time is valid; otherwise returns FALSE.

See also isValid().

void QTime::start ()

Sets this time to the current time. This is practical for timing:

QTime t;
t.start();
some_lengthy_task();
qDebug( "Time elapsed: %d ms", t.elapsed() );

See also restart(), elapsed(), and currentTime().

QString QTime::toString ( const QString & format ) const

Returns the time as a string. The format parameter determines the format of the result string.

These expressions may be used:

<center>.nf
</center>

^(the actual expression table didn't make it through this render, so here's its little placeholder gravestone πŸͺ¦)

All other input characters will be ignored.

Example format strings (assuming that the QTime is 14:13:09.042):

<center>.nf
</center>

^(same deal β€” table got eaten, placeholder preserved because we keep everything πŸ’œ)

If the time is an invalid time, then QString::null will be returned.

See also QDate::toString() and QDateTime::toString().


okay that's the whole first half and there's still more coming, don't go anywhere bestie, part 2 is right there β€” 🌈

πŸ’– QString QTime::toString ( Qt::DateFormat f = Qt::TextDate ) const πŸ’–

okay bestie, this is the overloaded member function β€” it's literally provided for convenience and behaves essentially like the above function. no cap.

It returns the time as a string. Milliseconds are not included β€” sorry babe, they're just not invited. The f parameter determines the format of the string.

  • If f is Qt::TextDate, the string format is HH:MM:SS; e.g. 1 second before midnight would be "23:59:59". ⏰
  • If f is Qt::ISODate, the string format corresponds to the ISO 8601 extended specification for representations of dates, which is also HH:MM:SS. ✨
  • If f is Qt::LocalDate, the string format depends on the locale settings of the system. 🌍

If the time is an invalid time, then QString::null will be returned. πŸ’€


QDataStream & operator<< ( QDataStream & s, const QTime & t )

Writes time t to the stream s. See also Format of the QDataStream operators. 🫢

QDataStream & operator>> ( QDataStream & s, QTime & t )

Reads a time from the stream s into t. See also Format of the QDataStream operators. 🫢


πŸ‘€ SEE ALSO πŸ‘€


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. πŸ‘‘


✍️ AUTHOR ✍️

Generated automatically from the source code. πŸ€–


πŸ› BUGS πŸ›

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. πŸ’–

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. πŸ“š

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qtime.3qt) and the Qt version (3.3.8). πŸ™


Trolltech AS Β· 2 February 2007 Β· QTime(3qt) β€” that's the footer bestie, ily bye πŸ’…βœ¨

πŸ“¦ where this page comes from