• PySide 模块
  • PySide.QtCore
  • 内容表

    上一话题

    QDateTime

    下一话题

    QDate

    QTime

    概要

    函数

    静态函数

    详细描述

    PySide.QtCore.QTime class provides clock time functions.

    A PySide.QtCore.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.

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

    A PySide.QtCore.QTime object is typically created either by giving the number of hours, minutes, seconds, and milliseconds explicitly, or by using the static function PySide.QtCore.QTime.currentTime() , which creates a PySide.QtCore.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.

    PySide.QtCore.QTime.hour() , PySide.QtCore.QTime.minute() , PySide.QtCore.QTime.second() ,和 PySide.QtCore.QTime.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 PySide.QtCore.QTime.toString() 函数。

    PySide.QtCore.QTime provides a full set of operators to compare two PySide.QtCore.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 PySide.QtCore.QTime.addSecs() or PySide.QtCore.QTime.addMSecs() functions. Correspondingly, the number of seconds or milliseconds between two times can be found using PySide.QtCore.QTime.secsTo() or PySide.QtCore.QTime.msecsTo() .

    PySide.QtCore.QTime can be used to measure a span of elapsed time using the PySide.QtCore.QTime.start() , PySide.QtCore.QTime.restart() ,和 PySide.QtCore.QTime.elapsed() 函数。

    class PySide.QtCore. QTime
    class PySide.QtCore. QTime ( QTime )
    class PySide.QtCore. QTime ( h , m [ , s=0 [ , ms=0 ] ] )
    参数:
    • h PySide.QtCore.int
    • ms PySide.QtCore.int
    • m PySide.QtCore.int
    • QTime PySide.QtCore.QTime
    • s PySide.QtCore.int

    Constructs a null time object. A null time can be a PySide.QtCore.QTime (0, 0, 0, 0) (i.e., midnight) object, except that PySide.QtCore.QTime.isNull() returns true and PySide.QtCore.QTime.isValid() returns false.

    构造时间采用小时 h ,分钟 m ,秒 s 和毫秒 ms .

    h 必须在范围 0 到 23, m and s 必须在范围 0 到 59,和 ms 必须在范围 0 到 999。

    PySide.QtCore.QTime. TimeFlag
    PySide.QtCore.QTime. __reduce__ ( )
    返回类型: PyObject
    PySide.QtCore.QTime. __repr__ ( )
    返回类型: PyObject
    PySide.QtCore.QTime. addMSecs ( ms )
    参数: ms PySide.QtCore.int
    返回类型: PySide.QtCore.QTime

    返回 PySide.QtCore.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 PySide.QtCore.QTime.addSecs() 范例。

    PySide.QtCore.QTime. addSecs ( secs )
    参数: secs PySide.QtCore.int
    返回类型: PySide.QtCore.QTime

    返回 PySide.QtCore.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.

    范例:

    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
    											
    static PySide.QtCore.QTime. currentTime ( )
    返回类型: PySide.QtCore.QTime

    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.

    PySide.QtCore.QTime. ds ( )
    返回类型: PySide.QtCore.int
    PySide.QtCore.QTime. elapsed ( )
    返回类型: PySide.QtCore.int

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

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

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

    警告

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

    static PySide.QtCore.QTime. fromString ( s [ , f=Qt.TextDate ] )
    参数:
    返回类型:

    PySide.QtCore.QTime

    static PySide.QtCore.QTime. fromString ( s , format )
    参数:
    • s – unicode
    • format – unicode
    返回类型:

    PySide.QtCore.QTime

    返回 PySide.QtCore.QTime represented by the string ,使用 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)
    m the minute without a leading zero (0 to 59)
    mm the minute with a leading zero (00 to 59)
    s the second without a leading zero (0 to 59)
    ss the second with a leading zero (00 to 59)
    z the milliseconds without leading zeroes (0 to 999)
    zzz the milliseconds with leading zeroes (000 to 999)
    AP interpret as an AM/PM time. AP must be either “AM” or “PM”.
    ap Interpret 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.

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

    If the format is not satisfied an invalid PySide.QtCore.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:

    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
    											

    QDateTime.toString() QTime.toString()

    PySide.QtCore.QTime. hour ( )
    返回类型: PySide.QtCore.int

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

    PySide.QtCore.QTime. isNull ( )
    返回类型: PySide.QtCore.bool

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

    PySide.QtCore.QTime. isValid ( )
    返回类型: PySide.QtCore.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.

    static PySide.QtCore.QTime. isValid ( h , m , s [ , ms=0 ] )
    参数:
    • h PySide.QtCore.int
    • m PySide.QtCore.int
    • s PySide.QtCore.int
    • ms PySide.QtCore.int
    返回类型:

    PySide.QtCore.bool

    这是重载函数。

    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.

    范例:

    QTime.isValid(21, 10, 30) # returns True
    QTime.isValid(22, 5,  62) # returns False
    											
    PySide.QtCore.QTime. minute ( )
    返回类型: PySide.QtCore.int

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

    PySide.QtCore.QTime. msec ( )
    返回类型: PySide.QtCore.int

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

    PySide.QtCore.QTime. msecsTo ( arg__1 )
    参数: arg__1 PySide.QtCore.QTime
    返回类型: PySide.QtCore.int

    Returns the number of milliseconds from this time to t 。若 t is earlier than this time, the number of milliseconds returned is negative.

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

    PySide.QtCore.QTime. __ne__ ( other )
    参数: other PySide.QtCore.QTime
    返回类型: PySide.QtCore.bool

    Returns true if this time is different from t ;否则返回 false。

    PySide.QtCore.QTime. __lt__ ( other )
    参数: other PySide.QtCore.QTime
    返回类型: PySide.QtCore.bool

    Returns true if this time is earlier than t ;否则返回 false。

    PySide.QtCore.QTime. __le__ ( other )
    参数: other PySide.QtCore.QTime
    返回类型: PySide.QtCore.bool

    Returns true if this time is earlier than or equal to t ;否则返回 false。

    PySide.QtCore.QTime. __eq__ ( other )
    参数: other PySide.QtCore.QTime
    返回类型: PySide.QtCore.bool

    Returns true if this time is equal to t ;否则返回 false。

    PySide.QtCore.QTime. __gt__ ( other )
    参数: other PySide.QtCore.QTime
    返回类型: PySide.QtCore.bool

    Returns true if this time is later than t ;否则返回 false。

    PySide.QtCore.QTime. __ge__ ( other )
    参数: other PySide.QtCore.QTime
    返回类型: PySide.QtCore.bool

    Returns true if this time is later than or equal to t ;否则返回 false。

    PySide.QtCore.QTime. restart ( )
    返回类型: PySide.QtCore.int

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

    This function is guaranteed to be atomic and is thus very handy for repeated measurements. Call PySide.QtCore.QTime.start() to start the first measurement, and PySide.QtCore.QTime.restart() for each later measurement.

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

    警告

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

    PySide.QtCore.QTime. second ( )
    返回类型: PySide.QtCore.int

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

    PySide.QtCore.QTime. secsTo ( arg__1 )
    参数: arg__1 PySide.QtCore.QTime
    返回类型: PySide.QtCore.int

    Returns the number of seconds from this time to t 。若 t is earlier than this time, the number of seconds returned is negative.

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

    PySide.QtCore.QTime.secsTo() does not take into account any milliseconds.

    PySide.QtCore.QTime. setHMS ( h , m , s [ , ms=0 ] )
    参数:
    • h PySide.QtCore.int
    • m PySide.QtCore.int
    • s PySide.QtCore.int
    • ms PySide.QtCore.int
    返回类型:

    PySide.QtCore.bool

    Sets the time to hour h ,分钟 m ,秒 s 和毫秒 ms .

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

    PySide.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())
    											
    PySide.QtCore.QTime. toPython ( )
    返回类型: PyObject
    PySide.QtCore.QTime. toString ( [ f=Qt.TextDate ] )
    参数: f PySide.QtCore.Qt.DateFormat
    返回类型: unicode
    PySide.QtCore.QTime. toString ( format )
    参数: format – unicode
    返回类型: unicode

    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 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 second without a leading zero (0 to 59)
    ss the second with a leading zero (00 to 59)
    z the milliseconds without leading zeroes (0 to 999)
    zzz the milliseconds with leading zeroes (000 to 999)
    AP or A use AM/PM display. AP will be replaced by either “AM” or “PM”.
    ap or a use am/pm display. ap will be replaced by either “am” or “pm”.
    t the timezone (for example “CEST”)

    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 PySide.QtCore.QTime is 14:13:09.042)

    格式 结果
    hh:mm:ss.zzz 14:13:09.042
    h:m:s ap 2:13:9 pm
    H:m:s a 14:13:9 pm

    If the datetime is invalid, an empty string will be returned. If format is empty, the default format “hh:mm:ss” is used.