1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
public static LocalDateTime getDateTimeOfTimestamp(long timestamp) { Instant instant = Instant.ofEpochMilli(timestamp); ZoneId zone = ZoneId.systemDefault(); return LocalDateTime.ofInstant(instant, zone); }
public static long getTimestampOfDateTime(LocalDateTime localDateTime) { ZoneId zone = ZoneId.systemDefault(); Instant instant = localDateTime.atZone(zone).toInstant(); return instant.toEpochMilli(); }
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime lastSyncLostTime = LocalDateTime.parse("2000-01-01 00:00:00",df);
Calendar calendar = Calendar.getInstance(); new Timestamp(TimeUtil.getTimestamp(calendar.getTime())
Timestamp time = Timestamp.from(Instant.now()); LocalDateTime localDateTime = time.toLocalDateTime();
Timestamp time = Timestamp.valueOf(LocalDateTime.now());
public static long getCalendarOfDateTimeAndTimestamp(LocalDateTime localDateTime) { LocalDateTime lastSyncLostTime = LocalDateTime.of(1999,1,1,0,0); long time = lastSyncLostTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();、 long time = lastSyncLostTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); } 、 public static Date getEndOfDay(Date date) { LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());; LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX); return Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant()); } public static Date getStartOfDay(Date date) { LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault()); LocalDateTime startOfDay = localDateTime.with(LocalTime.MIN); return Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant()); }
LocalDateTime today_start = LocalDateTime.of(LocalDate.now(), LocalTime.MIN); String td_st_str = today_start.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
LocalDateTime today_end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX); LocalDate today = LocalDate.now();
LocalDate firstday = LocalDate.of(today.getYear(),today.getMonth(),1);
LocalDate lastDay =today.with(TemporalAdjusters.lastDayOfMonth()); System.out.println("本月的第一天"+firstday); System.out.println("本月的最后一天"+lastDay);
LocalDate firstDayOfThisMonth = today.with(TemporalAdjusters.firstDayOfMonth());
LocalDate secondDayOfThisMonth = today.withDayOfMonth(2);
LocalDate lastDayOfThisMonth = today.with(TemporalAdjusters.lastDayOfMonth());
LocalDate firstDayOf2015 = lastDayOfThisMonth.plusDays(1);
LocalDate firstMondayOf2015 = LocalDate.parse("2015-01-01").with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY));
public static long getTodayStartTime() { return LocalDateTime.of(LocalDate.now(), LocalTime.MIN).toEpochSecond(ZoneOffset.of("+8")); }
public static long getTodayEndTime() { return LocalDateTime.of(LocalDate.now(), LocalTime.MAX).toEpochSecond(ZoneOffset.of("+8")); }
LocalDateTime from = LocalDateTime.of(2017, Month.JANUARY, 5, 10, 7, 0); LocalDateTime to = LocalDateTime.of(2017, Month.FEBRUARY, 5, 10, 7, 0); Duration duration = Duration.between(from, to);
long days = duration.toDays(); long hours = duration.toHours(); long minutes = duration.toMinutes(); long seconds = duration.getSeconds(); long milliSeconds = duration.toMillis(); long nanoSeconds = duration.toNanos(); Duration duration1 = Duration.of(5, ChronoUnit.DAYS); Duration duration2 = Duration.of(1000, ChronoUnit.MILLIS);
LocalDateTime of = LocalDateTime.of(LocalDate.now(), LocalTime.MAX); long between = ChronoUnit.SECONDS.between(LocalDateTime.now(), of);
Long millisecond = Instant.now().toEpochMilli(); Long second = Instant.now().getEpochSecond(); LocalDateTime now = LocalDateTime.now() Timestamp time = Timestamp.from(Instant.now());
|