【Android開発】タイムゾーンを考慮した日付・時刻の取得方法

タイムゾーンを考慮した日付・時刻の取得方法です。

1
2
3
4
5
6
7
8
9
10
import org.threeten.bp.ZoneId;
import org.threeten.bp.ZonedDateTime;

// 現在時刻
ZonedDateTime now = ZonedDateTime.now();
// 任意の日付
ZonedDateTime target = ZonedDateTime.of(2021, 04, 01, 0, 0, 0, 0, ZoneId.systemDefault());
if (now.compareTo(target_date) < 0) {
// targetが未来日付の場合はここに入る!
}

【Android開発】タイムゾーンを考慮した日付・時刻の取得方法

https://reon777.com/2021/03/23/android-ZonedDateTime/

Author

reon777

Posted on

2021-03-24

Updated on

2026-06-30

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×