当前位置:网站首页>Mutual conversion between qstring and qdatetime

Mutual conversion between qstring and qdatetime

2022-06-24 02:29:00 User 7108768

QDateTime yes Qt Date time class commonly used in , We often convert it into QString type , Or reverse conversion , The specific method is as follows .

1、QDateTime Convert to QString

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

QString strDate;QDateTime time;// Get the current time of the system time = QDateTime::currentTime();// In a fixed time format yyyy-MM-dd hh:mm:ss Save as string strDate = time.toString("yyyy-MM-dd hh:mm:ss"); 

2、QString Convert to QDateTime

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

// Define date 
QString dateContent = "2016-02-19 22:11:33" ;
QDateTime time;

time = QDateTime::fromString(dateContent, "yyyy-MM-dd hh:mm:ss");
原网站

版权声明
本文为[User 7108768]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/10/20211029134912986J.html