com.trolltech.qt.core
Class QTime

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QTime
All Implemented Interfaces:
QtJambiInterface, java.lang.Comparable

public class QTime
extends QtJambiObject
implements java.lang.Comparable

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 milliseconds.

QTime uses the 24-hour clock format; it has no concept of AM/PM. Unlike QDateTime, QTime knows nothing about time zones or daylight savings time (DST).

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 local 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 seconds or milliseconds between two times can be found using secsTo or msecsTo.

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

See Also:
QDate, QDateTime

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
QTime()
          Constructs a null time object.
QTime(int h, int m)
          Equivalent to QTime(h, m, 0, 0).
QTime(int h, int m, int s)
          Equivalent to QTime(h, m, s, 0).
QTime(int h, int m, int s, int ms)
          Constructs a time with hour h, minute m, seconds s and milliseconds ms.
 
Method Summary
 QTime addMSecs(int ms)
          Returns a QTime object containing a time ms milliseconds later than the time of this object (or earlier if ms is negative).
 QTime addSecs(int secs)
          Returns a QTime object containing a time secs seconds later than the time of this object (or earlier if secs is negative).
 int compareTo(java.lang.Object other)
           
static QTime currentTime()
          Returns the current time as reported by the system clock.
 int elapsed()
          Returns the number of milliseconds that have elapsed since the last time start or restart was called.
 boolean equals(java.lang.Object other)
          
static QTime fromNativePointer(QNativePointer nativePointer)
          This function returns the QTime instance pointed to by nativePointer
static QTime fromString(java.lang.String s)
          Equivalent to fromString(s, Qt::TextDate).
static QTime fromString(java.lang.String s, Qt.DateFormat f)
          Returns the time represented in the s as a QTime using the f given, or an invalid time if this is not possible.
static QTime fromString(java.lang.String s, java.lang.String format)
          Returns the QTime represented by the s, using the format given, or an invalid time if the string cannot be parsed.
 int hour()
          Returns the hour part (0 to 23) of the time.
 boolean isNull()
          Returns true if the time is null (i.e., the QTime object was constructed using the default constructor); otherwise returns false.
 boolean isValid()
          Returns true if the time is valid; otherwise returns false.
static boolean isValid(int h, int m, int s)
          Equivalent to isValid(h, m, s, 0).
static boolean isValid(int h, int m, int s, int ms)
          Returns true if the specified time is valid; otherwise returns false.
 int minute()
          Returns the minute part (0 to 59) of the time.
 int msec()
          Returns the millisecond part (0 to 999) of the time.
 int msecsTo(QTime arg__1)
          Returns the number of milliseconds from this time to arg__1.
static QNativePointer nativePointerArray(QTime[] array)
          This function returns a QNativePointer that is pointing to the specified QTime array.
 void readFrom(QDataStream arg__1)
          Reads a QTime from arg__1.
 int 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.
 int second()
          Returns the second part (0 to 59) of the time.
 int secsTo(QTime arg__1)
          Returns the number of seconds from this time to arg__1.
 boolean setHMS(int h, int m, int s)
          Equivalent to setHMS(h, m, s, 0).
 boolean setHMS(int h, int m, int s, int ms)
          Sets the time to hour h, minute m, seconds s and milliseconds ms.
 void start()
          Sets this time to the current time.
 java.lang.String toString()
          Equivalent to toString(Qt::TextDate).
 java.lang.String toString(Qt.DateFormat f)
          Returns the time as a string.
 java.lang.String toString(java.lang.String format)
          Returns the time as a string.
 void writeTo(QDataStream arg__1)
          Writes thisQTime to arg__1.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QTime

public QTime()

Constructs a null time object. A null time is identical to a QTime(0, 0, 0, 0) (i.e., midnight), except that isNull and isValid return false.

See Also:
isNull, isValid

QTime

public QTime(int h,
             int m,
             int s)

Equivalent to QTime(h, m, s, 0).


QTime

public QTime(int h,
             int m)

Equivalent to QTime(h, m, 0, 0).


QTime

public QTime(int h,
             int m,
             int s,
             int ms)

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

h must be in the range 0 to 23, m and s must be in the range 0 to 59, and ms must be in the range 0 to 999.

See Also:
isValid
Method Detail

addMSecs

public final QTime addMSecs(int ms)

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, msecsTo

addSecs

public final QTime addSecs(int secs)

Returns a QTime object containing a time secs seconds later than the time of this object (or earlier if secs 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, QDateTime::addSecs

elapsed

public final int elapsed()

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, restart

hour

public final int hour()

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

See Also:
minute, second, msec

isNull

public final boolean isNull()

Returns true if the time is null (i.e., the QTime object was constructed using the default constructor); otherwise returns false. A null time is also an invalid time.

See Also:
isValid

isValid

public final boolean isValid()

Returns true if the time is valid; otherwise returns false. For example, the time 23:30:55.746 is valid, but 24:12:30 is invalid.

See Also:
isNull

minute

public final int minute()

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

See Also:
hour, second, msec

msec

public final int msec()

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

See Also:
hour, minute, second

msecsTo

public final int msecsTo(QTime arg__1)

Returns the number of milliseconds from this time to arg__1. If arg__1 is earlier than this time, the number of milliseconds returned is negative.

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

See Also:
secsTo, addMSecs

writeTo

public final void writeTo(QDataStream arg__1)
Writes thisQTime to arg__1.


readFrom

public final void readFrom(QDataStream arg__1)
Reads a QTime from arg__1.


restart

public final int 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 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, currentTime

second

public final int second()

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

See Also:
hour, minute, msec

secsTo

public final int secsTo(QTime arg__1)

Returns the number of seconds from this time to arg__1. If arg__1 is earlier than this time, the number of seconds returned is negative.

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, QDateTime::secsTo

setHMS

public final boolean setHMS(int h,
                            int m,
                            int s)

Equivalent to setHMS(h, m, s, 0).


setHMS

public final boolean setHMS(int h,
                            int m,
                            int s,
                            int ms)

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

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

See Also:
isValid

start

public final void 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, currentTime

toString

public final java.lang.String toString(java.lang.String format)

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

These expressions may be used:

ExpressionOutput
hthe hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hhthe hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
Hthe hour without a leading zero (0 to 23, even with AM/PM display)
HHthe hour with a leading zero (00 to 23, even with AM/PM display)
mthe minute without a leading zero (0 to 59)
mmthe minute with a leading zero (00 to 59)
sthe second without a leading zero (0 to 59)
ssthe second with a leading zero (00 to 59)
zthe milliseconds without leading zeroes (0 to 999)
zzzthe milliseconds with leading zeroes (000 to 999)
AP or Ause AM/PM display. AP will be replaced by either "AM" or "PM".
ap or ause am/pm display. ap will be replaced by either "am" or "pm".

All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression. Two consecutive singlequotes ("''") are replaced by a singlequote in the output.

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

FormatResult
hh:mm:ss.zzz14:13:09.042
h:m:s ap2:13:9 pm
H:m:s a14:13:9 pm

If the datetime is invalid, an empty string will be returned.

See Also:
QDate::toString, QDateTime::toString

toString

public final java.lang.String toString()

Equivalent to toString(Qt::TextDate).

Overrides:
toString in class java.lang.Object

toString

public final java.lang.String toString(Qt.DateFormat f)

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. (However, unlike that ISO 8601 specifies, dates before 1582 are handled as Julian dates, not Gregorian dates. This might change in a future version of Qt.)

If f is Qt::LocalDate or Qt::SystemLocaleDate, the string format depends on the locale settings of the system. Identical to calling QLocale::system().toString(time, QLocale::ShortFormat). Qt::LocalDate has been deprecated, please use Qt::SystemLocaleDate instead.

If f is Qt::LocaleDate, the string format depends on the default application locale. This is the locale set with QLocale::setDefault(), or the system locale if no default locale has been set. Identical to calling QLocale().toString(time, QLocale::ShortFormat);

If f is Qt::LocalDate, the string format depends on the locale settings of the system.

If the datetime is invalid, an empty string will be returned.


currentTime

public static QTime currentTime()

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.


fromString

public static QTime fromString(java.lang.String s,
                               java.lang.String format)

Returns the QTime represented by the s, using the format given, or an invalid time if the string cannot be parsed.

These expressions may be used for the format:

ExpressionOutput
hthe hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hhthe hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
mthe minute without a leading zero (0 to 59)
mmthe minute with a leading zero (00 to 59)
sthe second without a leading zero (0 to 59)
ssthe second with a leading zero (00 to 59)
zthe milliseconds without leading zeroes (0 to 999)
zzzthe milliseconds with leading zeroes (000 to 999)
APinterpret as an AM/PM time. AP must be either "AM" or "PM".
apInterpret as an AM/PM time. ap must be either "am" or "pm".

All other input characters will be treated as text. Any sequence of characters that are enclosed in single quotes will also be treated as text and not be used as an expression.

    QTime time = QTime::fromString("1mm12car00", "m'mm'hcarss");
    // time is 12:01.00

If the format is not satisfied an invalid QTime is returned. Expressions that do not expect leading zeroes to be given (h, m, s and z) are greedy. This means that they will use two digits even if this puts them outside the range of accepted values and leaves too few digits for other sections. For example, the following string could have meant 00:07:10, but the m will grab two digits, resulting in an invalid time:

    QTime time = QTime::fromString("00:710", "hh:ms"); // invalid

Any field that is not represented in the format will be set to zero. For example:

    QTime time = QTime::fromString("1.30", "m.s");
    // time is 00:01:30.000

QDateTime::toString() QTime::toString()

See Also:
QDateTime::fromString, QDate::fromString, QDate::toString

fromString

public static QTime fromString(java.lang.String s)

Equivalent to fromString(s, Qt::TextDate).


fromString

public static QTime fromString(java.lang.String s,
                               Qt.DateFormat f)

Returns the time represented in the s as a QTime using the f given, or an invalid time if this is not possible.

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


isValid

public static boolean isValid(int h,
                              int m,
                              int s)

Equivalent to isValid(h, m, s, 0).


isValid

public static boolean isValid(int h,
                              int m,
                              int s,
                              int ms)

Returns true if the specified time is valid; otherwise returns false.

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

Example:

    QTime::isValid(21, 10, 30); // returns true
    QTime::isValid(22, 5,  62); // returns false


fromNativePointer

public static QTime fromNativePointer(QNativePointer nativePointer)
This function returns the QTime instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

nativePointerArray

public static QNativePointer nativePointerArray(QTime[] array)
This function returns a QNativePointer that is pointing to the specified QTime array.

Parameters:
array - the array that the returned pointer will point to.
Returns:
a QNativePointer that is pointing to the specified array.

equals

public boolean equals(java.lang.Object other)

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object other)
Specified by:
compareTo in interface java.lang.Comparable