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

1、QDateTime 转换为 QString

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

view plain copy to clipboard print ?
  1. QString strBuffer; 
  2. QDateTime time; 
  3.  
  4. time = QDateTime::currentDateTime(); 
  5.  
  6. strBuffer = time.toString("yyyy-MM-dd hh:mm:ss"); 
  7.  
  8. // strBuffer = 2010-07-02 17:35:00 
[cpp] view plain copy print ?
  1. QString strBuffer; 
  2. QDateTime time; 
  3.  
  4. time = QDateTime::currentDateTime(); 
  5.  
  6. strBuffer = time.toString("yyyy-MM-dd hh:mm:ss"); 
  7.  
  8. // strBuffer = 2010-07-02 17:35:00 
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]

view plain copy to clipboard print ?
  1. QString strBuffer; 
  2. QDateTime time; 
  3.  
  4. strBuffer = "2010-07-02 17:35:00"
  5.  
  6. time = QDateTime::fromString(strBuffer, "yyyy-MM-dd hh:mm:ss"); 

你可能感兴趣的:(编程,String,qt,2010)