私は自分のアプリで 2 つのタイム パイカーを使用しています。1 つは FROM-Time 用、もう 1 つは TO-Time 用です。ここで、TO-Time を設定する際に FROM-Time よりも短くしてはならず、FROM-Time よりも短い時間を変更できないことを確認したいと思います。
1661 次
2 に答える
0
現在の日付/時刻を取得するには、新しい Date オブジェクトを作成するだけです。
日付を比較するには、Date.compareTo() を使用します。
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = new Date();
int difference = now.compareTo(formatter.parse(data));
ドキュメントによると、違いは次のとおりです。
引数 Date がこの Date と等しい場合は値 0。この Date が Date 引数より前の場合は 0 未満の値。この Date が Date 引数より後の場合は 0 より大きい値。
if (difference == 0) {
// the dates are equal
}
else if (difference < 0) {
// the date is before now
}
else {
// the date is after now
}
于 2014-01-03T07:11:39.250 に答える