いつも忘れるので、ここでメモ
Java8 時間類
LocalDateTime→UinxTimestamp(ミリ秒)
LocalDateTime yestoday = LocalDateTime.now().minusDays(1).withHour(0); // 分、秒、ミリ秒まで細かく設定。
long millis = ZonedDateTime.of(yestoday, ZoneId.systemDefault()).toInstant().toEpochMilli();
以下のこのページからパックリ:https://javazuki.com/articles/sql-date-conver-to-datetime.html
[Java]Unixタイムスタンプと日時の変換 (ZonedDateTime, LocalDateTime)
Timesatmp→LocalDateTime
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
LocalDateTime localDateTime = timestamp.toLocalDateTime();
LocalDateTime→Timesatmp
LocalDateTime localDateTime = LocalDateTime.now();
Timestamp timestamp = Timestamp.valueOf(localDateTime);
java.sql.Date→LocalDate
java.sql.Date javaSqlDate = new java.sql.Date(System.currentTimeMillis());
LocalDate localDate = javaSqlDate.toLocalDate();
LocalDate→java.sql.Date
LocalDate localDate = LocalDate.now();
java.sql.Date javaSqlDate = java.sql.Date.valueOf(localDate);
java.sql.Time→LocalTime
java.sql.Time javaSqlTime = new java.sql.Time(System.currentTimeMillis());
LocalTime localTime = javaSqlTime.toLocalTime();
LocalTime→java.sql.Time
LocalTime localTime = LocalTime.now();
java.sql.Time javaSqlTime = java.sql.Time.valueOf(localTime);
LocalDateTime → java.util.Date
ZoneId zone = ZoneId.systemDefault();
ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, zone);
Instant instant = zonedDateTime.toInstant();
return Date.from(instant);
java.util.Date → LocalDateTime
Instant instant = date.toInstant();
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
参考になった記事
https://qiita.com/riekure/items/d83d4ea5d8a19a267453
以上!