Qt时间
獲取系統當前時間并設置顯示格式
QDateTime current_date_time = QDateTime::currentDateTime();
QString current_date = current_date_time.toString("yyyy-MM-dd hh:mm:ss ddd");
例:2013-05-24 13:09:10 周五
獲取當前時間時、分、秒 范圍:小時(0--23)、分鐘(0--59)、秒(0--59)、毫秒(0--999) QTime current_time = QTime::currentTime(); int hour = current_time.hour(); int minute = current_time.minute(); int second = current_time.second(); int msec = current_time.msec();
比較日期大小 //獲取當前時間及文件緩存時間QDateTime currentDateTime = QDateTime::currentDateTime();QDateTime dateTime = QDateTime::fromString(strDate, sDateTimeFormat);
//獲取文件緩存一個月之后的時間QDateTime afterOneMonthDateTime = dateTime.addMonths(1);
//如果緩存時間超過一個月,則刪除qint64 nSecs = afterOneMonthDateTime.secsTo(currentDateTime);if (nSecs > 0){QFile::remove(strFilePath);}這里是舉的一個小例子(刪除一個月以前的緩存文件),當然也可以使用格式化后的字符串進行比較!
這些都是比較常用的,也很好記。。。
注: 技術在于交流、溝通,轉載請注明出處并保持作品的完整性。 作者:╰☆奮斗ing?孩子`??原文:http://blog.sina.com.cn/s/blog_a6fb6cc90101djki.html。
獲取當前時間時、分、秒 范圍:小時(0--23)、分鐘(0--59)、秒(0--59)、毫秒(0--999) QTime current_time = QTime::currentTime(); int hour = current_time.hour(); int minute = current_time.minute(); int second = current_time.second(); int msec = current_time.msec();
比較日期大小 //獲取當前時間及文件緩存時間QDateTime currentDateTime = QDateTime::currentDateTime();QDateTime dateTime = QDateTime::fromString(strDate, sDateTimeFormat);
//獲取文件緩存一個月之后的時間QDateTime afterOneMonthDateTime = dateTime.addMonths(1);
//如果緩存時間超過一個月,則刪除qint64 nSecs = afterOneMonthDateTime.secsTo(currentDateTime);if (nSecs > 0){QFile::remove(strFilePath);}這里是舉的一個小例子(刪除一個月以前的緩存文件),當然也可以使用格式化后的字符串進行比較!
這些都是比較常用的,也很好記。。。
注: 技術在于交流、溝通,轉載請注明出處并保持作品的完整性。 作者:╰☆奮斗ing?孩子`??原文:http://blog.sina.com.cn/s/blog_a6fb6cc90101djki.html。
總結
- 上一篇: 二维数组数组名的使用
- 下一篇: 如何QLayout内部的成员部件之间从左