QTime Class Reference
[QtCore module]
QTime类提供时间函数
#include <QTime>
注意:所有函数是可重入的
公共函数:
  QTime()
  QTime(int h,int m,int s=0,int ms=0)
QTime  addMSecs(int ms)const
QTime addSecs ( int s ) const
int elapsed () const
int hour () const
bool isNull () const
bool isValid () const
int minute () const
int msec () const
int msecsTo ( const QTime & t ) const
int restart ()
int second () const
int secsTo ( const QTime & t ) const
bool setHMS ( int h, int m, int s, int ms = 0 )
void start ()
QString toString ( const QString & format ) const
QString toString ( Qt::DateFormat format = Qt::TextDate ) const
bool operator!= ( const QTime & t ) const
bool operator< ( const QTime & t ) const
bool operator<= ( const QTime & t ) const
bool operator== ( const QTime & t ) const
bool operator> ( const QTime & t ) const
bool operator>= ( const QTime & t ) const
静态公共函数:
QTime currentTime ()
QTime fromString ( const QString & string, Qt::DateFormat format = Qt::TextDate )
QTime fromString ( const QString & string, const QString & format )
bool isValid ( int h, int m, int s, int ms = 0 )
相关的非成员:
QDataStream & operator<< ( QDataStream & out, const QTime & time )
QDataStream & operator>> ( QDataStream & in, QTime & time )
详细描述:
QTime对象包含一个时钟时间,小时数,分钟,秒,和毫秒从午夜起。他能读目前的时间,量出消逝的一段时间。他提供函数为了比较时间,熟练控制一个时间,通过毫秒数。
QTime使用24小时时钟格式。他没有AM和PM的概念。不像QDateTime。QTime不知道时区或者日光节约时间(夏令时间)(DST)
一个QTime对象典型的创建,要么通过设置小时,分钟,秒,毫秒;或者使用静态函数currentTime(),他创造QTime对象包含系统当地的时间。注意他的准确性依赖于基本的操作系统的准确性。不是所有的系统提供一毫秒的精确性。
hour(), minute(), second(), and msec() 函数提供对应的时间。相同的信息被提供在text格式通过函数toString()
QTime提供全套的操作来比较两个QTime对象。一个时间是被认为更小,如果他比另一个更早。
addSecs()或者addMSecs()函数能够得到一个被给的秒或者毫秒比一个被给的时间晚多少。同样的,secsTo()或者msecsTo()函数能够得到两个时间之间的秒或者毫秒。
QTime也能使用函数start(),restart(),elapsed()函数来测量一段消逝的时间。
成员函数文件:
QTime::QTime ()
构建一个空的时间。一个空时间可以是QTime(0,0,0,0),此时isNull()返回true,isValid()返回false
QTime::QTime ( int h, int m, int s = 0, int ms = 0 )
注意:h在[0,23],m和s在[0,59],ms在[0,999];
QTime QTime::addMSecs ( int ms ) const
返回一个QTime对象,包含一个时间ms,表示比这个对象晚多少ms。如果ms是负值,表示早多少ms。
QTime QTime::addSecs ( int s ) const
例子:
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
QTime QTime::currentTime ()   [static]
返回当前时间
int QTime::elapsed () const
返回已经消逝的ms数,自从上一个时间start()或者restart()被调用。
注意:计数器变成0,当24小时过去了。
警告:如果系统时钟设置已经被改变,自从start()或者restart()被调用,那么结果不可预知。这个能发生,当夏令时间开或者关。
QTime QTime::fromString ( const QString & string, Qt::DateFormat format = Qt::TextDate )   [static]
注意:fromString()使用一个c的当地编码字符串来转换ms到一个float值。如果默认的当地不是c,这可能导致两个变化尝试。这应该被认为是一个执行详情。
QTime QTime::fromString ( const QString & string, const QString & format )   [static]
下面的表达来表示格式:
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".
所有其他的表达将被认为是text格式。
QTime time = QTime::fromString("1mm12car00", "m'mm'hcarss");
 // time is 12:01.00
如果格式不对,一个无效的QTime被返回。
QTime time = QTime::fromString("00:710", "hh:ms"); // invalid
QTime time = QTime::fromString("1.30", "m.s");
 // time is 00:01:30.000
int QTime::hour () const
bool QTime::isNull () const
bool QTime::isValid () const
QTime::isValid(21, 10, 30); // returns true
 QTime::isValid(22, 5,  62); // returns false
int QTime::minute () const
int QTime::msec () const
nt QTime::msecsTo ( const QTime & t ) const
返回这个时间到t的毫秒数。
注意:QTime返回一天之内的时间差,所以ms范围-8640000到8640000
int QTime::restart ()
设置这个时间为当前时间。返回毫秒数,已经消逝的,自从start()或者restart()被调用。
int QTime::second () const
int QTime::secsTo ( const QTime & t ) const
bool QTime::setHMS ( int h, int m, int s, int ms = 0 )
设置小时,分钟,秒,毫秒
void QTime::start ()
设置时间为目前的时间。
QTime t;
 t.start();
 some_lengthy_task();
 qDebug("Time elapsed: %d ms", t.elapsed());
QString QTime::toString ( const QString & format ) const
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
QString QTime::toString ( Qt::DateFormat format = Qt::TextDate ) const
如果格式是Qt::TextDate,字符串格式是HH:MM:SS.
如果格式是Qt::ISODate,字符串格式与iso8601格式相同,也是HH:MM:SS
Constant Value Description
Qt::TextDate 0 The default Qt format, which includes the day and month name, the day number in the month, and the year in full. The day and month names will be short, localized names. This is basically equivalent to using the date format string, "ddd MMM d yyyy". SeeQDate::toString() for more information.
Qt::ISODate 1 ISO 8601 extended format: either YYYY-MM-DD for dates or YYYY-MM-DDTHH:MM:SS for combined dates and times.
Qt::SystemLocaleShortDate ? The short format used by the operating system.
Qt::SystemLocaleLongDate ? The long format used by the operating system.
Qt::DefaultLocaleShortDate ? The short format specified by the application's locale.
Qt::DefaultLocaleLongDate ? The long format used by the application's locale.
Qt::SystemLocaleDate 2 This enum value is deprecated. Use Qt::SystemLocaleShortDate instead (or Qt::SystemLocaleLongDate if you want long dates).
Qt::LocaleDate ? This enum value is deprecated. Use Qt::DefaultLocaleShortDate instead (or Qt::DefaultLocaleLongDate if you want long dates).
Qt::LocalDate SystemLocaleDate This enum value is deprecated. Use Qt::SystemLocaleShortDate instead (or Qt::SystemLocaleLongDate if you want long dates).
bool QTime::operator!= ( const QTime & t ) const
bool QTime::operator< ( const QTime & t ) const
bool QTime::operator<= ( const QTime & t ) const
bool QTime::operator== ( const QTime & t ) const
bool QTime::operator> ( const QTime & t ) const
bool QTime::operator>= ( const QTime & t ) const
相关的非成员:
QDataStream & operator<< ( QDataStream & out, const QTime & time )
QDataStream & operator>> ( QDataStream & in, QTime & time )