当前时间时间戳转换为日期
//当前时间毫秒的时间戳转换为日期Date millisecondDate= new Date(System.currentTimeMillis());//格式化时间SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String millisecondStrings = formatter.format(millisecondDate);System.out.println(millisecondStrings);
//当前时间秒的时间戳转换为日期
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//字符串类型的秒级时间戳String currentTime = "1657519062";Long date = Long.valueOf(currentTime);//String类型String date_time = formatter.format(new Date(date*1000L));System.out.println(date_time);//Date类型Date times=formatter.parse(date_time);System.out.println(times);//Date转为LocalDateTime类型Instant instant = times.toInstant();ZoneId zoneId = ZoneId.systemDefault();LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
System.out.println(localDateTime );