QDateTime dateTime;
QString dateTime_str = dateTime.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
//从字符串转换为毫秒(需完整的年月日时分秒)
datetime..toMSecsSinceEpoch();
//从字符串转换为秒(需完整的年月日时分秒) 同样
datetime.toTime_t();
// 上边这个方法已经过时了
datetime..toSecsSinceEpoch();
//从毫秒转换到年月日时分秒
datetime.fromMSecsSinceEpoch(1315193829218).toString("yyyy-MM-dd hh:mm:ss:zzz");
//从秒转换到年月日时分秒(若有zzz,则为000)
datetime.fromTime_t(1315193829).toString("yyyy-MM-dd hh:mm:ss[:zzz]");
QString和QDateTime互转换
QDateTime 转换为 QString
QString strBuffer;
QDateTime time;
time = QDateTime::currentDateTime();
strBuffer = time.toString("yyyy-MM-dd hh:mm:ss");
// strBuffer = 2010-07-02 17:35:00
QString 转换为 QDateTime
QString strBuffer;
QDateTime time;
strBuffer = "2010-07-02 17:35:00";
time = QDateTime::fromString(strBuffer, "yyyy-MM-dd hh:mm:ss");