QT编程技巧.QString和QDateTime之间的相互转换

来源:互联网 发布:阿里云小号 编辑:程序博客网 时间:2024/06/06 03:09

1、QDateTime 转换为 QString

 

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

QString strBuffer;QDateTime time;time = QDateTime::currentDateTime();strBuffer = time.toString("yyyy-MM-dd hh:mm:ss");// strBuffer = 2010-07-02 17:35:00


 

2、QString 转换为 QDateTime

 

QDateTime QDateTime::fromString ( const QString & string, const QString & format )   [static]


QString strBuffer;QDateTime time;strBuffer = "2010-07-02 17:35:00";time = QDateTime::fromString(strBuffer, "yyyy-MM-dd hh:mm:ss");


转自:http://blog.csdn.net/coderwu/article/details/5709803


原创粉丝点击