Java Instant get day end millisecond

Description

Java Instant get day end millisecond

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class Main {
  public static void main(String[] argv) {
    long l = getDayTailMills(new Date().getTime());
    System.out.println(l);//from w  w w  .j  a v a 2s . c  om
  }

  public static long getDayTailMills(long timestamp) {
    Instant instant = Instant.ofEpochMilli(timestamp);
    ZonedDateTime dateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
    ZonedDateTime dateHead = ZonedDateTime.of(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth(),
        23, 59, 59, 1000000000 - 1, ZoneId.systemDefault());
    return dateHead.toInstant().toEpochMilli();
  }
}



PreviousNext

Related