QTime¶
The QTime
class provides clock time functions. More…
Synopsis¶
Functions¶
def
__eq__
(rhs)def
__ge__
(rhs)def
__gt__
(rhs)def
__le__
(rhs)def
__lt__
(rhs)def
__ne__
(rhs)def
__reduce__
()def
__repr__
()def
addMSecs
(ms)def
addSecs
(secs)def
hour
()def
isNull
()def
isValid
()def
minute
()def
msec
()def
msecsSinceStartOfDay
()def
msecsTo
(t)def
second
()def
secsTo
(t)def
setHMS
(h, m, s[, ms=0])def
toPython
()def
toString
([f=Qt.TextDate])def
toString
(format)def
toString
(format)
Static functions¶
def
currentTime
()def
fromMSecsSinceStartOfDay
(msecs)def
fromString
(string, format)def
fromString
(string, format)def
fromString
(string, format)def
fromString
(string[, format=Qt.TextDate])def
fromString
(string[, format=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 provides functions for comparing times and for manipulating a time by adding a number of milliseconds. QTime
objects should be passed by value rather than by reference to const; they simply package int
.
QTime
uses the 24-hour clock format; it has no concept of AM/PM. Unlike QDateTime
, 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 function currentTime()
, which creates a QTime
object that represents the system’s local time.
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.
The addSecs()
and addMSecs()
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 using secsTo()
or msecsTo()
.
QTime
provides a full set of operators to compare two QTime
objects; an earlier time is considered smaller than a later one; if A. msecsTo
(B) is positive, then A < B.
QTime
objects can also be created from a text representation using fromString()
and converted to a string representation using toString()
. All conversion to and from string formats is done using the C locale. For localized conversions, see QLocale
.
- class PySide6.QtCore.QTime¶
PySide6.QtCore.QTime(QTime)
PySide6.QtCore.QTime(h, m[, s=0[, ms=0]])
- Parameters
m – int
QTime –
PySide6.QtCore.QTime
ms – int
s – int
h – int
Constructs a null time object. For a null time, isNull()
returns true
and isValid()
returns false
. If you need a zero time, use QTime
(0, 0). For the start of a day, see startOfDay()
.
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
- PySide6.QtCore.QTime.TimeFlag¶
- PySide6.QtCore.QTime.__reduce__()¶
- Return type
object
- PySide6.QtCore.QTime.__repr__()¶
- Return type
object
- PySide6.QtCore.QTime.addMSecs(ms)¶
- Parameters
ms – int
- Return type
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.
Returns a null time if this time is invalid.
See also
- PySide6.QtCore.QTime.addSecs(secs)¶
- Parameters
secs – int
- Return type
Returns a QTime
object containing a time s
seconds later than the time of this object (or earlier if s
is negative).
Note that the time will wrap if it passes midnight.
Returns a null time if this time is invalid.
Example:
QTime n(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:00See also
- static PySide6.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.
Furthermore, only increases within each day; it shall drop by 24 hours each time midnight passes; and, beside this, changes in it may not correspond to elapsed time, if a daylight-saving transition intervenes.
See also
- static PySide6.QtCore.QTime.fromMSecsSinceStartOfDay(msecs)¶
- Parameters
msecs – int
- Return type
Returns a new QTime
instance with the time set to the number of msecs
since the start of the day, i.e. since 00:00:00.
If msecs
falls outside the valid range an invalid QTime
will be returned.
See also
- static PySide6.QtCore.QTime.fromString(string, format)¶
- Parameters
string –
QStringView
format –
QStringView
- Return type
This is an overloaded function.
- static PySide6.QtCore.QTime.fromString(string[, format=Qt.TextDate])
- Parameters
string –
QStringView
format –
DateFormat
- Return type
This is an overloaded function.
- static PySide6.QtCore.QTime.fromString(string, format)
- Parameters
string – str
format –
QStringView
- Return type
This is an overloaded function.
- static PySide6.QtCore.QTime.fromString(string[, format=Qt.TextDate])
- Parameters
string – str
format –
DateFormat
- Return type
Returns the time represented in the string
as a QTime
using the format
given, or an invalid time if this is not possible.
See also
- static PySide6.QtCore.QTime.fromString(string, format)
- Parameters
string – str
format – str
- Return type
Returns the QTime
represented by the string
, using the format
given, or an invalid time if the string cannot be parsed.
These expressions may be used for the format:
Expression
Output
h
The hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh
The hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
H
The hour without a leading zero (0 to 23, even with AM/PM display)
HH
The hour with a leading zero (00 to 23, even with AM/PM display)
m
The minute without a leading zero (0 to 59)
mm
The minute with a leading zero (00 to 59)
s
The whole second, without any leading zero (0 to 59)
ss
The whole second, with a leading zero where applicable (00 to 59)
z
The fractional part of the second, to go after a decimal point, without trailing zeroes (0 to 999). Thus “
s.z
" reports the seconds to full available (millisecond) precision without trailing zeroes.zzz
The fractional part of the second, to millisecond precision, including trailing zeroes where applicable (000 to 999).
AP or A
Interpret as an AM/PM time. A/AP will match ‘AM’ or ‘PM’.
ap or a
Interpret as an am/pm time. a/ap will match ‘am’ or ‘pm’.
All other input characters will be treated as text. Any non-empty sequence of characters enclosed in single quotes will also be treated (stripped of the quotes) as text and not be interpreted as expressions.
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 (or three, for z) 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:
time = QTime.fromString("00:710", "hh:ms") # invalid()
Any field that is not represented in the format will be set to zero. For example:
time = QTime.fromString("1.30", "m.s") # time is 00:01:30.000
Note
If localized forms of am or pm (the AP, ap, A or a formats) are used, please use system()
.toTime().
See also
- PySide6.QtCore.QTime.hour()¶
- Return type
int
Returns the hour part (0 to 23) of the time.
Returns -1 if the time is invalid.
- PySide6.QtCore.QTime.isNull()¶
- Return type
bool
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
- static PySide6.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
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
- PySide6.QtCore.QTime.isValid()
- Return type
bool
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
- PySide6.QtCore.QTime.minute()¶
- Return type
int
Returns the minute part (0 to 59) of the time.
Returns -1 if the time is invalid.
- PySide6.QtCore.QTime.msec()¶
- Return type
int
Returns the millisecond part (0 to 999) of the time.
Returns -1 if the time is invalid.
- PySide6.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
- PySide6.QtCore.QTime.msecsTo(t)¶
- Parameters
- Return type
int
Returns the number of milliseconds from this time to t
. If t
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
- PySide6.QtCore.QTime.__ne__(rhs)¶
- Parameters
rhs –
PySide6.QtCore.QTime
- Return type
bool
- PySide6.QtCore.QTime.__lt__(rhs)¶
- Parameters
rhs –
PySide6.QtCore.QTime
- Return type
bool
- PySide6.QtCore.QTime.__le__(rhs)¶
- Parameters
rhs –
PySide6.QtCore.QTime
- Return type
bool
- PySide6.QtCore.QTime.__eq__(rhs)¶
- Parameters
rhs –
PySide6.QtCore.QTime
- Return type
bool
- PySide6.QtCore.QTime.__gt__(rhs)¶
- Parameters
rhs –
PySide6.QtCore.QTime
- Return type
bool
- PySide6.QtCore.QTime.__ge__(rhs)¶
- Parameters
rhs –
PySide6.QtCore.QTime
- Return type
bool
- PySide6.QtCore.QTime.second()¶
- Return type
int
Returns the second part (0 to 59) of the time.
Returns -1 if the time is invalid.
- PySide6.QtCore.QTime.secsTo(t)¶
- Parameters
- Return type
int
Returns the number of seconds from this time to t
. If t
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.
- PySide6.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
, 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
- PySide6.QtCore.QTime.toPython()¶
- Return type
object
- PySide6.QtCore.QTime.toString(format)¶
- Parameters
format –
QStringView
- Return type
str
- PySide6.QtCore.QTime.toString([f=Qt.TextDate])
- Parameters
f –
DateFormat
- Return type
str
This is an overloaded function.
Returns the time as a string. The format
parameter determines the format of the string.
If format
is TextDate
, the string format is HH:mm:ss; e.g. 1 second before midnight would be “23:59:59”.
If format
is ISODate
, 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 the format
ISODateWithMs
, which corresponds to HH:mm:ss.zzz.
If the format
is RFC2822Date
, 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
- PySide6.QtCore.QTime.toString(format)
- Parameters
format – str
- Return type
str
© 2022 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.