Use DateTimeFormatter in favor of SimpleDateFormat

See gh-19142
pull/19159/head
dreis2211 5 years ago committed by Stephane Nicoll
parent aca094d82f
commit 8a730ff630

@ -27,8 +27,8 @@ import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@ -106,7 +106,7 @@ public class HeapDumpWebEndpoint {
}
private File createTempFile(boolean live) throws IOException {
String date = new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date());
String date = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm").format(LocalDateTime.now());
File file = File.createTempFile("heapdump" + date + (live ? "-live" : ""), ".hprof");
file.delete();
return file;

@ -23,8 +23,8 @@ import java.lang.management.ManagementFactory;
import java.lang.management.MonitorInfo;
import java.lang.management.RuntimeMXBean;
import java.lang.management.ThreadInfo;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -47,8 +47,8 @@ class PlainTextThreadDumpFormatter {
}
private void writePreamble(PrintWriter writer) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
writer.println(dateFormat.format(new Date()));
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
writer.println(dateFormat.format(LocalDateTime.now()));
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
writer.printf("Full thread dump %s (%s %s):%n", runtime.getVmName(), runtime.getVmVersion(),
System.getProperty("java.vm.info"));

@ -16,9 +16,9 @@
package org.springframework.boot.info;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Properties;
/**
@ -108,11 +108,11 @@ public class GitProperties extends InfoProperties {
if (epoch != null) {
return String.valueOf(epoch);
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
try {
return String.valueOf(format.parse(s).getTime());
return String.valueOf(format.parse(s, Instant::from).toEpochMilli());
}
catch (ParseException ex) {
catch (DateTimeParseException ex) {
return s;
}
}

Loading…
Cancel
Save