QT QDateTime

    QDateTime daytime = QDateTime::currentDateTime();
    QString strTime = daytime.toString("dd.MM.yyyy hh:mm:ss.zzz");
    qDebug()<<strTime;
    QDateTime daytime1 = QDateTime::fromString(strTime,"dd.MM.yyyy hh:mm:ss.zzz");
    qDebug()<<daytime1;

Public Functions

 

 

QDateTime()

 

QDateTime(const QDate &date)

 

QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec = Qt::LocalTime)

 

QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec, int offsetSeconds)

 

QDateTime(const QDate &date, const QTime &time, const QTimeZone &timeZone)

 

QDateTime(const QDateTime &other)

 

~QDateTime()

QDateTime

addDays(qint64 ndays) const

QDateTime

addMSecs(qint64 msecs) const

QDateTime

addMonths(int nmonths) const

QDateTime

addSecs(qint64 s) const

QDateTime

addYears(int nyears) const

QDate

date() const

qint64

daysTo(const QDateTime &other) const

bool

isDaylightTime() const

bool

isNull() const

bool

isValid() const

qint64

msecsTo(const QDateTime &other) const

int

offsetFromUtc() const

qint64

secsTo(const QDateTime &other) const

void

setDate(const QDate &date)

void

setMSecsSinceEpoch(qint64 msecs)

void

setOffsetFromUtc(int offsetSeconds)

void

setTime(const QTime &time)

void

setTimeSpec(Qt::TimeSpec spec)

void

setTimeZone(const QTimeZone &toZone)

void

setTime_t(uint seconds)

void

swap(QDateTime &other)

QTime

time() const

Qt::TimeSpec

timeSpec() const

QTimeZone

timeZone() const

QString

timeZoneAbbreviation() const

CFDateRef

toCFDate() const

QDateTime

toLocalTime() const

qint64

toMSecsSinceEpoch() const

NSDate *

toNSDate() const

QDateTime

toOffsetFromUtc(int offsetSeconds) const

QString

toString(const QString &format) const

QString

toString(Qt::DateFormat format = Qt::TextDate) const

QDateTime

toTimeSpec(Qt::TimeSpec spec) const

QDateTime

toTimeZone(const QTimeZone &timeZone) const

uint

toTime_t() const

QDateTime

toUTC() const

bool

operator!=(const QDateTime &other) const

bool

operator<(const QDateTime &other) const

bool

operator<=(const QDateTime &other) const

QDateTime &

operator=(QDateTime &&other)

QDateTime &

operator=(const QDateTime &other)

bool

operator==(const QDateTime &other) const

bool

operator>(const QDateTime &other) const

bool

operator>=(const QDateTime &other) const

Static Public Members

 

QDateTime

currentDateTime()

QDateTime

currentDateTimeUtc()

qint64

currentMSecsSinceEpoch()

QDateTime

fromCFDate(CFDateRef date)

QDateTime

fromMSecsSinceEpoch(qint64 msecs)

QDateTime

fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetSeconds = 0)

QDateTime

fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone)

QDateTime

fromNSDate(const NSDate *date)

QDateTime

fromString(const QString &string, Qt::DateFormat format = Qt::TextDate)

QDateTime

fromString(const QString &string, const QString &format)

QDateTime

fromTime_t(uint seconds)

QDateTime

fromTime_t(uint seconds, Qt::TimeSpec spec, int offsetSeconds = 0)

QDateTime

fromTime_t(uint seconds, const QTimeZone &timeZone)

Related Non-Members

 

QDataStream &

operator<<(QDataStream &out, const QDateTime &dateTime)

QDataStream &

operator>>(QDataStream &in, QDateTime &dateTime)

Detailed Description

The QDateTime class provides date and time functions.

A QDateTime object contains a calendar date and a clock time (a "datetime"). It is a combination of the QDate and QTime classes. It can read the current datetime from the system clock. It provides functions for comparing datetimes and for manipulating a datetime by adding a number of seconds, days, months, or years.

A QDateTime object is typically created either by giving a date and time explicitly in the constructor, or by using the static function currentDateTime() that returns a QDateTime object set to the system clock's time. The date and time can be changed with setDate() and setTime(). A datetime can also be set using the setTime_t() function that takes a POSIX-standard "number of seconds since 00:00:00 on January 1, 1970" value. The fromString() function returns a QDateTime, given a string and a date format used to interpret the date within the string.

The date() and time() functions provide access to the date and time parts of the datetime. The same information is provided in textual format by the toString() function.

QDateTime provides a full set of operators to compare two QDateTime objects, where smaller means earlier and larger means later.

You can increment (or decrement) a datetime by a given number of milliseconds using addMSecs(), seconds using addSecs(), or days using addDays(). Similarly, you can use addMonths() and addYears(). The daysTo() function returns the number of days between two datetimes, secsTo() returns the number of seconds between two datetimes, and msecsTo() returns the number of milliseconds between two datetimes.

QDateTime can store datetimes as local time or as UTC. QDateTime::currentDateTime() returns a QDateTime expressed as local time; use toUTC() to convert it to UTC. You can also use timeSpec() to find out if a QDateTime object stores a UTC time or a local time. Operations such as addSecs() and secsTo() are aware of daylight-saving time (DST).

Note: QDateTime does not account for leap seconds.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值