fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.time.*;
  7. import java.time.format.DateTimeFormatter;
  8.  
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  16. LocalDateTime localDateTime = LocalDateTime.now();
  17. ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.of("UTC"));
  18. String formattedString = zonedDateTime.format(DATE_FORMATTER);
  19. System.out.println(formattedString);
  20. }
  21.  
  22. public static Date getDateAtMidnight(Date date, String timeZone) {
  23. ZonedDateTime zonedDateTime = Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.of(timeZone));
  24. LocalDate localDate = LocalDate.of(zonedDateTime.getYear(), zonedDateTime.getMonth(),
  25. zonedDateTime.getDayOfMonth());
  26. zonedDateTime = localDate.atStartOfDay(ZoneId.of(timeZone));
  27. return new Date(zonedDateTime.toEpochSecond() * 1000);
  28. }
  29. }
Success #stdin #stdout 0.1s 49012KB
stdin
Standard input is empty
stdout
2022-05-27 10:40