LoginSignup
1
1

More than 1 year has passed since last update.

LocalDateTimeで指定日の23時59分59秒を作る

Posted at

散々悩んだ結果先輩がサラっと作っていた、精進が足りない

LocalDateTime localDateTime = LocalDateTime.now();
LocalDateTime ldt = localDateTime.truncatedTo(ChronoUnit.DAYS).plusDays(1).minusSeconds(1);

ついでに、LocalDateTime型→Date型にする場合

public static final ZoneId ZONE = ZoneId.of("Asia/Tokyo");
    
ZonedDateTime zonedDateTime = ldt.atZone(ZONE);
Date date = Date.from(zonedDateTime.toInstant());

これpaizaでやるとUTC時間になるの何でだろう、now()時点ではJST時間なのに

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1