Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

QTime Class Reference

The QTime class provides clock time functions. More...

#include <qdatetime.h>

List of all member functions.

Public Members

Static Public Members

  • QTime currentTime ()
  • QTime fromString ( const QString & s, Qt::DateFormat f = Qt::TextDate )
  • bool isValid ( int h, int m, int s, int ms = 0 )

Related Functions

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

Detailed Description

The QTime class provides clock time functions.

A QTime object contains a clock time, i.e. the number of hours, minutes, seconds, and milliseconds since midnight. It can read the current time from the system clock and measure a span of elapsed time. It provides functions for comparing times and for manipulating a time by adding a number of (milli)seconds.

QTime uses 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.

A QTime object is typically created either by giving the number of hours, minutes, seconds, and milliseconds explicitly, or by using the static function currentTime(), which creates a QTime object that contains the system's clock time. Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

The hour(), minute(), second(), and msec() functions provide access to the number of hours, minutes, seconds, and milliseconds of the time. The same information is provided in textual format by the toString() function.

QTime provides a full set of operators to compare two QTime objects. One time is considered smaller than another if it is earlier than the other.

The time a given number of seconds or milliseconds later than a given time can be found using the addSecs() or addMSecs() functions. Correspondingly, the number of (milli)seconds between two times can be found using the secsTo() or msecsTo() functions.

QTime can be used to measure a span of elapsed time using the start(), restart(), and elapsed() functions.

See also QDate, QDateTime and Time and Date.


Member Function Documentation

QTime::QTime ()

Constructs the time 0 hours, minutes, seconds and milliseconds, i.e. 00:00:00.000 (midnight). 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.

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. See addSecs() for an example.

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 () [static]

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.

Examples: aclock/aclock.cpp, dclock/dclock.cpp, t12/cannon.cpp and tictac/tictac.cpp.

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.

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.

Example: tictac/tictac.cpp.

bool QTime::isNull () const

Returns TRUE if the time is equal to 00:00:00.000; otherwise returns FALSE. A null time is valid.

See also isValid().

bool QTime::isValid () const

Returns TRUE if the time is valid; otherwise returns FALSE. The time 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: aclock/aclock.cpp and tictac/tictac.cpp.

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 -86400 and 86400s.

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 and is thus very handy for repeated measurements. Call start() to start the first measurement and then restart() for each later measurement.

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();                     // start clock
    ... // some lengthy task
    qDebug( "%d\n", t.elapsed() ); // prints the number of msecs 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:

Expression Output
h the hour without a leading zero (0..23 or 1..12 if AM/PM display)
hh the hour with a leading zero (00..23 or 01..12 if AM/PM display)
m the minute without a leading zero (0..59)
mm the minute with a leading zero (00..59)
s the second whithout a leading zero (0..59)
ss the second whith a leading zero (00..59)
z the milliseconds without leading zeroes (0..999)
zzz the milliseconds with leading zeroes (000..999)
AP use AM/PM display. AP will be replaced by either "AM" or "PM".
ap use am/pm display. ap will be replaced by either "am" or "pm".

All other input characters will be ignored.

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

Format Result
hh:mm:ss.zzz 14:13:09.042
h:m:s ap 2:13:9 pm

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

QString QTime::toString ( Qt::DateFormat f = Qt::TextDate ) const

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

Returns the time as a string. Milliseconds are not included. 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.


Related Functions

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.


This file is part of the Qt toolkit. Copyright © 1995-2002 Trolltech. All Rights Reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 23
  2. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 46
  3. Une nouvelle ère d'IHM 3D pour les automobiles, un concept proposé par Digia et implémenté avec Qt 3
  4. Qt Creator 2.5 est sorti en beta, l'EDI supporte maintenant plus de fonctionnalités de C++11 2
  5. PySide devient un add-on Qt et rejoint le Qt Project et le modèle d'open gouvernance 1
  6. Vingt sociétés montrent leurs décodeurs basés sur Qt au IPTV World Forum, en en exploitant diverses facettes (déclaratif, Web, widgets) 0
  7. Thread travailleur avec Qt en utilisant les signaux et les slots, un article de Christophe Dumez traduit par Thibaut Cuvelier 1
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 50
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 23
  5. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 46
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
Page suivante

Le Qt Developer Network au hasard

Logo

Installation de PySide : binaires et compilation

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 3.0
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web