String DATE_FORMAT = "yyyy-MM-dd"; LocalDate localDate = LocalDate.now(); long startTime = localDate.atTime(0, 0, 0).toEpochSecond(ZoneOffset.of("+8")); long endTime = localDate.plusDays(1).atTime(0, 0, 0).toEpochSecond(ZoneOffset.of("+8")) - 1; String result = localDate.format(DateTimeFormatter.ofPattern(DATE_FORMAT)); System.out.println(result); System.out.println(startTime); System.out.println(endTime); System.out.println("*******************"); Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT); String time = df.format(date); System.out.println(df.parse(time).getTime());
运行结果:
2019-02-13 1549987200 1550073599 ******************* 1549987200000