QTime Class Reference

[QtCore module]

该QTIME类提供时钟时间的功能。More…

Methods

  • __init__ (self)
  • __init__ (self, int h, int m, int second = 0, int msec = 0)
  • __init__ (self, QTime)
  • QTime addMSecs (self, int ms)
  • QTime addSecs (self, int secs)
  • int elapsed (self)
  • int hour (self)
  • bool isNull (self)
  • bool isValid (self)
  • int minute (self)
  • int msec (self)
  • int msecsTo (self, QTime)
  • int restart (self)
  • int second (self)
  • int secsTo (self, QTime)
  • bool setHMS (self, int h, int m, int s, int msec = 0)
  • start (self)
  • datetime.time toPyTime (self)
  • QString toString (self, Qt.DateFormat format = Qt.TextDate)
  • QString toString (self, QString format)

Static Methods

  • QTime currentTime ()
  • QTime fromString (QString string, Qt.DateFormat format = Qt.TextDate)
  • QTime fromString (QString s, QString format)
  • bool isValid (int h, int m, int s, int msec = 0)

Special Methods

  • int __bool__ (self)
  • bool __eq__ (self, QTime other)
  • bool __ge__ (self, QTime other)
  • bool __gt__ (self, QTime other)
  • int __hash__ (self)
  • bool __le__ (self, QTime other)
  • bool __lt__ (self, QTime other)
  • bool __ne__ (self, QTime other)
  • str __repr__ (self)

Detailed Description

这个类可以醃制。

也可以使用一个Python的datetime对象,每当一个QTime预计。

该QTIME类提供时钟时间的功能。

一个QTIME对象包含一个时钟时间,即小时,分钟,秒和毫秒自午夜数。它可以从系统时钟读取当前时间,并测量经过的时间跨度。它提供的功能,用于比较时间和用于通过将一个数毫秒的操作时间。

QTIME使用24小时时钟格式,它具有AM / PM的概念。不像QDateTime, QTIME一无所知时区或日光节约时间(DST ) 。

一个QTIME对象通常是通过给小时,分钟,秒和毫秒数显式,或使用静态函数创建currentTime( ) ,它会创建一个包含系统的本地时间QTIME对象。请注意,精度依赖于底层操作系统的准确性;不是所有的系统都提供1毫秒的精度。

hour( )minute( )second()和msec( )函数可以访问的时,分,秒和时间的毫秒数。相同的信息被提供以文本格式toString()函数。

QTIME提供了一整套的运营商来比较两个QTIME对象。一时间被认为比另一个更小,如果它是早于其他。

的时间的秒或毫秒的给定数量超过一个给定的时间可以用找到的addSecs()或addMSecs()函数。与此相对应,几秒钟或两个时间之间的毫秒数可以使用被发现secsTo()或msecsTo( ) 。

QTIME可用于使用测量的经过时间跨度的start( )restart()和elapsed()函数。


Method Documentation

  1. QTime.__init__ (self)

构造一个空的时间对象。空时间可QTime(0,0 ,0,0 )(即,午夜)对象,不同的是isNull( )返回True,isValid( )返回False 。

See also isNull()和isValid( ) 。

  1. QTime.__init__ (self, int h, int m, int second = 0, int msec = 0)

构造一个时间小时h,分m,秒s和毫秒ms

h必须在范围0〜23,ms必须在范围0 〜59,ms必须在范围0到999 。

See also isValid( ) 。

  1. QTime.__init__ (self, QTime)
  1. QTime QTime.addMSecs (self, int ms)

返回QTime对象包含时间ms毫秒迟于该对象的时间(或更早版本,如果ms是负的) 。

需要注意的是,如果它通过午夜的时候会换行。看addSecs( )的一个例子。

See also addSecs( )msecsTo()和QDateTime.addMSecs( ) 。

  1. QTime QTime.addSecs (self, int secs)

返回QTime对象包含时间s秒迟于该对象的时间(或更早版本,如果s是负的) 。

需要注意的是,如果它通过午夜的时候会换行。

例如:

  1. [QTime]($docs-qtime.html) n(14, 0, 0); // n == 14:00:00
  2. [QTime]($docs-qtime.html) t;
  3. t = n.addSecs(70); // t == 14:01:10
  4. t = n.addSecs(-70); // t == 13:58:50
  5. t = n.addSecs(10 * 60 * 60 + 5); // t == 00:00:05
  6. t = n.addSecs(-15 * 60 * 60); // t == 23:00:00

See also addMSecs( )secsTo()和QDateTime.addSecs( ) 。

  1. QTime QTime.currentTime ()

[

返回当前时间所报告的系统时钟。

请注意,精度依赖于底层操作系统的准确性;不是所有的系统都提供1毫秒的精度。

  1. int QTime.elapsed (self)

]($docs-qtime.html)

返回自上一次已经过的毫秒数start()或restart( )被调用。

请注意,计数器回到零24小时内的最后一次通话后,start()或重启。

请注意,精度依赖于底层操作系统的准确性;不是所有的系统都提供1毫秒的精度。

Warning:如果系统的时钟设置已自最后一次修改start()或restart( )被调用,结果是不确定的。日光节约时间开启或关闭可能发生这种情况。

See also start()和restart( ) 。

  1. QTime QTime.fromString (QString string, Qt.DateFormat format = Qt.TextDate)

传回所代表的时间string作为QTime使用format给予,或无效的时间,如果这是不可能的。

需要注意的是fromString ( )使用“ C”语言环境编码的字符串,以毫秒为单位转换为float值。如果默认locale是不是“ C” ,这可能会导致两个转换的尝试(如果转换失败的默认语言环境) 。这应该被视为一个实现细节。

  1. QTime QTime.fromString (QString s, QString format)

返回QTime由表示string使用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”.

所有其他输入的字符将被视为文本。括在单引号中的任何字符序列也将被视为文本,而不是作为一个表达式。

  1. [QTime]($docs-qtime.html) time = [QTime]($docs-qtime.html).fromString("1mm12car00", "m'mm'hcarss");
  2. // time is 12:01.00

如果该格式不被满足的无效QTime返回。不指望前导零应给予(H , M,S和z )表达式是贪婪的。这意味着它们将使用两个数字,即使这使他们接受的值的范围外,叶太少位数为其他部分。例如,下面的字符串可能意味着0时07分10秒,但米将抓住两个数字,从而导致无效时间:

  1. [QTime]($docs-qtime.html) time = [QTime]($docs-qtime.html).fromString("00:710", "hh:ms"); // invalid

未在该格式表示的任何字段将被设置为零。例如:

  1. [QTime]($docs-qtime.html) time = [QTime]($docs-qtime.html).fromString("1.30", "m.s");
  2. // time is 00:01:30.000

QDateTime.toString( )QTime.toString( )

See also QDateTime.fromString( )QDate.fromString()和QDate.toString( ) 。

  1. int QTime.hour (self)

返回时间的小时部分( 0到23) 。

See also minute( )second()和msec( ) 。

  1. bool QTime.isNull (self)

返回True如果时间为null (即,QTime使用默认构造函数)构造分布,否则返回False 。一个空的时间也是无效的时间。

See also isValid( ) 。

  1. bool QTime.isValid (self)

返回True如果时间是有效的,否则返回False 。例如,时间23:30:55.746是有效的,但24:12:30是无效的。

See also isNull( ) 。

  1. bool QTime.isValid (int h, int m, int s, int msec = 0)

这是一个重载函数。

返回True如果指定的时间是有效的,否则返回False 。

时间是有效的,如果h取值范围为0〜23,ms的范围是0 〜59,ms的范围是从0到999 。

例如:

  1. [QTime]($docs-qtime.html).isValid(21, 10, 30); // returns true
  2. [QTime]($docs-qtime.html).isValid(22, 5, 62); // returns false
  1. int QTime.minute (self)

返回时间的分钟部分( 0到59) 。

See also hour( )second()和msec( ) 。

  1. int QTime.msec (self)

返回时间的毫秒部分( 0到999 ) 。

See also hour( )minute()和second( ) 。

  1. int QTime.msecsTo (self, QTime)

返回的毫秒数从这个时候t。如果t早于当前时间,返回的毫秒数是负的。

因为QTime测量时间在一天之内,并有86400秒,一天的结果总是之间-86400000和86400000毫秒。

See also secsTo( )addMSecs()和QDateTime.msecsTo( ) 。

  1. int QTime.restart (self)

设置此时间为当前时间,并返回自上一次已经过的毫秒数start( )或重新启动()被调用。

此功能保证是原子的,因此是非常方便的重复测量。通话start( ) ,开始第一次测量,并重新启动( )为每个后来的测量。

请注意,计数器回到零24小时内的最后一次通话后,start( )或重新启动( ) 。

Warning:如果系统的时钟设置已自最后一次修改start( )或重新启动( )被调用,结果是不确定的。日光节约时间开启或关闭可能发生这种情况。

See also start( )elapsed()和currentTime( ) 。

  1. int QTime.second (self)

返回的时间的第二部分(0到59)。

See also hour( )minute()和msec( ) 。

  1. int QTime.secsTo (self, QTime)

返回的秒数从这个时候t。如果t早于当前时间,返回的秒数为负。

因为QTime测量时间在一天之内,并有一天86400秒,结果总是-86400和86400之间。

secsTo ()不考虑任何毫秒。

See also addSecs()和QDateTime.secsTo( ) 。

  1. bool QTime.setHMS (self, int h, int m, int s, int msec = 0)

设置时间小时h,分m,秒s和毫秒ms

h必须在范围0〜23,ms必须在范围0 〜59,ms必须在范围0到999 。返回True如果设定的时间是有效的,否则返回False 。

See also isValid( ) 。

  1. QTime.start (self)

设置这个时间设置为当前时间。这是不切实际的时机:

  1. [QTime]($docs-qtime.html) t;
  2. t.start();
  3. some_lengthy_task();
  4. qDebug("Time elapsed: %d ms", t.elapsed());

See also restart( )elapsed()和currentTime( ) 。

  1. datetime.time QTime.toPyTime (self)
  1. QString QTime.toString (self, Qt.DateFormat format = Qt.TextDate)

返回时间为一个字符串。该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 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”)

所有其它输入的字符将被忽略。括在singlequotes任何字符序列将被视为文本,而不是被用作表达。连续两singlequotes ( “’’” )是由singlequote输出所取代。

例如格式字符串(假设QTime是14:13:09.042 )

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

如果日期时间是无效的,空字符串将被返回。如果format是空的,默认的格式为“ HH : MM:SS ”一词。

See also QDate.toString()和QDateTime.toString( ) 。

  1. QString QTime.toString (self, QString format)

这是一个重载函数。

返回时间为一个字符串。毫秒不包括在内。该format参数确定字符串的格式。

If format is Qt.TextDate,字符串格式为HH : MM:SS ;例如午夜在1秒将是“ 23:59:59 ” 。

If format is Qt.ISODate,字符串格式对应于ISO 8601扩展规格的日期,这也是HH的表示: MM:SS 。 (然而,与ISO 8601 ,日期1582年10月15日之前为Julian日期,而不是公历日期的处理方式。见Use of Gregorian and Julian Calendars。这可能会改变的Qt的未来版本。 )

如果format is Qt.SystemLocaleShortDate or Qt.SystemLocaleLongDate,字符串格式取决于系统的区域设置。相同的调用QLocale.system( ) 。的toString (时间,QLocale.ShortFormat)或QLocale.system( ) 。的toString (时间,QLocale.LongFormat) 。

如果format is Qt.DefaultLocaleShortDate or Qt.DefaultLocaleLongDate,字符串格式依赖于默认应用程序的语言环境。这就是语言环境设置QLocale.setDefault( )或系统区域设置,如果没有默认区域设置已定。相同的调用QLocale ( ) 。的toString (时间,QLocale.ShortFormat)或QLocale ( ) 。的toString (时间,QLocale.LongFormat) 。

如果时间是无效的,空字符串将被返回。

  1. int QTime.__bool__ (self)
  1. bool QTime.__eq__ (self, QTime other)
  1. bool QTime.__ge__ (self, QTime other)
  1. bool QTime.__gt__ (self, QTime other)
  1. int QTime.__hash__ (self)
  1. bool QTime.__le__ (self, QTime other)
  1. bool QTime.__lt__ (self, QTime other)
  1. bool QTime.__ne__ (self, QTime other)
  1. str QTime.__repr__ (self)