QTime¶
Synopsis¶
Functions¶
def
__eq__
(other)def
__ge__
(other)def
__gt__
(other)def
__le__
(other)def
__lt__
(other)def
__ne__
(other)def
__reduce__
()def
__repr__
()def
addMSecs
(ms)def
addSecs
(secs)def
elapsed
()def
hour
()def
isNull
()def
isValid
()def
minute
()def
msec
()def
msecsSinceStartOfDay
()def
msecsTo
(arg__1)def
restart
()def
second
()def
secsTo
(arg__1)def
setHMS
(h, m, s[, ms=0])def
start
()def
toPython
()def
toString
([f=Qt.TextDate])def
toString
(format)
Static functions¶
def
currentTime
()def
fromMSecsSinceStartOfDay
(msecs)def
fromString
(s, format)def
fromString
(s[, f=Qt.TextDate])def
isValid
(h, m, s[, ms=0])
Detailed Description¶
A
QTime
object contains a clock time, which it can express as the numbers 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. UnlikeQDateTime
,QTime
knows nothing about time zones or daylight-saving 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 functioncurrentTime()
, which creates aQTime
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()
, andmsec()
functions provide access to the number of hours, minutes, seconds, and milliseconds of the time. The same information is provided in textual format by thetoString()
function.The
addSecs()
andaddMSecs()
functions provide the time a given number of seconds or milliseconds later than a given time. Correspondingly, the number of seconds or milliseconds between two times can be found usingsecsTo()
ormsecsTo()
.
QTime
provides a full set of operators to compare twoQTime
objects; an earlier time is considered smaller than a later one; if A.msecsTo
(B) is positive, then A < B.
QTime
can be used to measure a span of elapsed time using thestart()
,restart()
, andelapsed()
functions.
-
class
QTime
¶ QTime(QTime)
QTime(h, m[, s=0[, ms=0]])
- param h
int
- param m
int
- param ms
int
- param s
int
- param QTime
Constructs a null time object. A null time can be a
QTime
(0, 0, 0, 0) (i.e., midnight) object, except thatisNull()
returnstrue
andisValid()
returnsfalse
.Constructs a time with hour
h
, minutem
, secondss
and millisecondsms
.h
must be in the range 0 to 23,m
ands
must be in the range 0 to 59, andms
must be in the range 0 to 999.See also
-
PySide2.QtCore.QTime.
TimeFlag
¶
-
PySide2.QtCore.QTime.
__reduce__
()¶ - Return type
PyObject
-
PySide2.QtCore.QTime.
__repr__
()¶ - Return type
PyObject
-
PySide2.QtCore.QTime.
addMSecs
(ms)¶ - Parameters
ms –
int
- Return type
Returns a
QTime
object containing a timems
milliseconds later than the time of this object (or earlier ifms
is negative).Note that the time will wrap if it passes midnight. See
addSecs()
for an example.Returns a null time if this time is invalid.
See also
-
PySide2.QtCore.QTime.
addSecs
(secs)¶ - Parameters
secs –
int
- Return type
Returns a
QTime
object containing a times
seconds later than the time of this object (or earlier ifs
is negative).Note that the time will wrap if it passes midnight.
Returns a null time if this time is invalid.
Example:
n = QTime(14, 0, 0) # n == 14:00:00 t = QTime() 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
-
static
PySide2.QtCore.QTime.
currentTime
()¶ - Return type
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.
-
PySide2.QtCore.QTime.
elapsed
()¶ - Return type
int
Returns the number of milliseconds that have elapsed since the last time
start()
orrestart()
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.
-
static
PySide2.QtCore.QTime.
fromMSecsSinceStartOfDay
(msecs)¶ - Parameters
msecs –
int
- Return type
Returns a new
QTime
instance with the time set to the number ofmsecs
since the start of the day, i.e. since 00:00:00.If
msecs
falls outside the valid range an invalidQTime
will be returned.See also
-
static
PySide2.QtCore.QTime.
fromString
(s[, f=Qt.TextDate])¶ - Parameters
s – unicode
f –
DateFormat
- Return type
-
static
PySide2.QtCore.QTime.
fromString
(s, format) - Parameters
s – unicode
format – unicode
- Return type
-
PySide2.QtCore.QTime.
hour
()¶ - Return type
int
Returns the hour part (0 to 23) of the time.
Returns -1 if the time is invalid.
-
PySide2.QtCore.QTime.
isNull
()¶ - Return type
bool
Returns
true
if the time is null (i.e., theQTime
object was constructed using the default constructor); otherwise returns false. A null time is also an invalid time.See also
-
PySide2.QtCore.QTime.
isValid
()¶ - Return type
bool
Returns
true
if the time is valid; otherwise returnsfalse
. For example, the time 23:30:55.746 is valid, but 24:12:30 is invalid.See also
-
static
PySide2.QtCore.QTime.
isValid
(h, m, s[, ms=0]) - Parameters
h –
int
m –
int
s –
int
ms –
int
- Return type
bool
This is an overloaded function.
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
ands
are in the range 0 to 59, andms
is in the range 0 to 999.Example:
QTime.isValid(21, 10, 30) # returns True QTime.isValid(22, 5, 62) # returns False
-
PySide2.QtCore.QTime.
minute
()¶ - Return type
int
Returns the minute part (0 to 59) of the time.
Returns -1 if the time is invalid.
-
PySide2.QtCore.QTime.
msec
()¶ - Return type
int
Returns the millisecond part (0 to 999) of the time.
Returns -1 if the time is invalid.
-
PySide2.QtCore.QTime.
msecsSinceStartOfDay
()¶ - Return type
int
Returns the number of msecs since the start of the day, i.e. since 00:00:00.
See also
-
PySide2.QtCore.QTime.
msecsTo
(arg__1)¶ - Parameters
arg__1 –
QTime
- Return type
int
Returns the number of milliseconds from this time to
t
. Ift
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.Returns 0 if either time is invalid.
See also
-
PySide2.QtCore.QTime.
__ne__
(other)¶ - Parameters
other –
QTime
- Return type
bool
Returns
true
if this time is different fromt
; otherwise returnsfalse
.
-
PySide2.QtCore.QTime.
__eq__
(other)¶ - Parameters
other –
QTime
- Return type
bool
Returns
true
if this time is equal tot
; otherwise returnsfalse
.
-
PySide2.QtCore.QTime.
__gt__
(other)¶ - Parameters
other –
QTime
- Return type
bool
Returns
true
if this time is later thant
; otherwise returnsfalse
.
-
PySide2.QtCore.QTime.
__ge__
(other)¶ - Parameters
other –
QTime
- Return type
bool
Returns
true
if this time is later than or equal tot
; otherwise returnsfalse
.
-
PySide2.QtCore.QTime.
restart
()¶ - Return type
int
Sets this time to the current time and returns the number of milliseconds that have elapsed since the last time
start()
or 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 for each later measurement.Note that the counter wraps to zero 24 hours after the last call to
start()
or .Warning
If the system’s clock setting has been changed since the last time
start()
or was called, the result is undefined. This can happen when daylight-saving time is turned on or off.See also
-
PySide2.QtCore.QTime.
second
()¶ - Return type
int
Returns the second part (0 to 59) of the time.
Returns -1 if the time is invalid.
-
PySide2.QtCore.QTime.
secsTo
(arg__1)¶ - Parameters
arg__1 –
QTime
- Return type
int
Returns the number of seconds from this time to
t
. Ift
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.does not take into account any milliseconds.
Returns 0 if either time is invalid.
-
PySide2.QtCore.QTime.
setHMS
(h, m, s[, ms=0])¶ - Parameters
h –
int
m –
int
s –
int
ms –
int
- Return type
bool
Sets the time to hour
h
, minutem
, secondss
and millisecondsms
.h
must be in the range 0 to 23,m
ands
must be in the range 0 to 59, andms
must be in the range 0 to 999. Returnstrue
if the set time is valid; otherwise returnsfalse
.See also
-
PySide2.QtCore.QTime.
start
()¶ Sets this time to the current time. This is practical for timing:
t = QTime() t.start() some_lengthy_task() print ("Time elapsed: %d ms" % t.elapsed())
See also
-
PySide2.QtCore.QTime.
toPython
()¶ - Return type
PyObject
-
PySide2.QtCore.QTime.
toString
([f=Qt.TextDate])¶ - Parameters
f –
DateFormat
- Return type
unicode
This is an overloaded function.
Returns the time as a string. The
format
parameter determines the format of the string.If
format
isTextDate
, the string format is HH:mm:ss; e.g. 1 second before midnight would be “23:59:59”.If
format
isISODate
, the string format corresponds to the ISO 8601 extended specification for representations of dates, represented by HH:mm:ss. To include milliseconds in the ISO 8601 date, use theformat
ISODateWithMs
, which corresponds to HH:mm:ss.zzz.If the
format
isSystemLocaleShortDate
orSystemLocaleLongDate
, the string format depends on the locale settings of the system. Identical to callingsystem()
.toString
(time,ShortFormat
) orsystem()
.toString
(time,LongFormat
).If the
format
isDefaultLocaleShortDate
orDefaultLocaleLongDate
, the string format depends on the default application locale. This is the locale set withsetDefault()
, or the system locale if no default locale has been set. Identical to callingShortFormat)
orLongFormat)
.If the
format
isRFC2822Date
, the string is formatted in an RFC 2822 compatible way. An example of this formatting is “23:59:20”.If the time is invalid, an empty string will be returned.
See also
-
PySide2.QtCore.QTime.
toString
(format) - Parameters
format – unicode
- Return type
unicode
© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.