「Qtの基礎 - 日時」の版間の差分

ナビゲーションに移動 検索に移動
 
212行目: 212行目:
  else if (now < compareDate) qDebug() << "指定の日時より前です";
  else if (now < compareDate) qDebug() << "指定の日時より前です";
  else                        qDebug() << "指定の日時と同じです";
  else                        qDebug() << "指定の日時と同じです";
</syntaxhighlight>
<br>
以下の例では、現在の日本時間と比較して2日以内かどうかを確認している。<br>
<syntaxhighlight lang="c++">
#include <QDateTime>
QString dateString = "2024年3月31日 12時35分";
QDateTime date = QDateTime::fromString(dateString, "yyyy年M月d日 h時m分");
QDateTime nowDate = QDateTime::currentDateTime();
nowDate.setTimeZone(QTimeZone("Asia/Tokyo"));
// 現在の日付から2日以内かどうかを確認
if (date.daysTo(nowDate) <= 2) {
    std::cout << QString("2日以内です").toStdString() << std::endl;
}
  </syntaxhighlight>
  </syntaxhighlight>
<br><br>
<br><br>

案内メニュー