Merge pull request #19142 from dreis2211

* pr/19142:
  Use DateTimeFormatter in favor of SimpleDateFormat

Closes gh-19142
pull/19159/head
Stephane Nicoll 5 years ago
commit f0a503f097

@ -27,8 +27,8 @@ import java.lang.reflect.Method;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files; import java.nio.file.Files;
import java.text.SimpleDateFormat; import java.time.LocalDateTime;
import java.util.Date; import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -106,7 +106,7 @@ public class HeapDumpWebEndpoint {
} }
private File createTempFile(boolean live) throws IOException { 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 file = File.createTempFile("heapdump" + date + (live ? "-live" : ""), ".hprof");
file.delete(); file.delete();
return file; return file;

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

@ -16,9 +16,9 @@
package org.springframework.boot.info; package org.springframework.boot.info;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Properties; import java.util.Properties;
/** /**
@ -108,11 +108,11 @@ public class GitProperties extends InfoProperties {
if (epoch != null) { if (epoch != null) {
return String.valueOf(epoch); 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 { 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; return s;
} }
} }

Loading…
Cancel
Save