2020import java .net .URI ;
2121import java .net .URL ;
2222import java .time .Duration ;
23- import java .time .Instant ;
23+ import java .time .ZonedDateTime ;
2424import java .util .ArrayList ;
2525import java .util .Arrays ;
2626import java .util .Collections ;
@@ -79,7 +79,6 @@ public class Server extends Handler.Wrapper implements Attributes
7979 private static final Logger LOG = LoggerFactory .getLogger (Server .class );
8080 private static final String __serverInfo = "jetty/" + Server .getVersion ();
8181
82- private final Instant startupInstant = Instant .now ();
8382 private final AttributeContainerMap _attributes = new AttributeContainerMap ();
8483 private final ThreadPool _threadPool ;
8584 private final Scheduler _scheduler ;
@@ -89,6 +88,7 @@ public class Server extends Handler.Wrapper implements Attributes
8988 private final AutoLock _dateLock = new AutoLock ();
9089 private final MimeTypes .Mutable _mimeTypes = new MimeTypes .Mutable ();
9190 private String _serverInfo = __serverInfo ;
91+ private ZonedDateTime startupTime ;
9292 private boolean _openEarly = true ;
9393 private boolean _stopAtShutdown ;
9494 private boolean _dumpAfterStart ;
@@ -549,28 +549,30 @@ public HttpField getDateField()
549549 }
550550
551551 /**
552- * @return the UTC startup instant
552+ * @return the startup date and time in the system timezone, or {@code null} if not started
553553 */
554- public Instant getStartupInstant ()
554+ public ZonedDateTime getStartupTime ()
555555 {
556- return startupInstant ;
556+ return startupTime ;
557557 }
558558
559559 /**
560- * @return the time, in milliseconds, since this Server was created.
560+ * @return the time, in milliseconds, since this Server was started
561561 */
562562 public long getUptimeMillis ()
563563 {
564- return Duration .between (startupInstant , Instant .now ()).toMillis ();
564+ return startupTime == null ? 0 : Duration .between (startupTime , ZonedDateTime .now ()).toMillis ();
565565 }
566566
567567 @ Override
568568 protected void doStart () throws Exception
569569 {
570570 try
571571 {
572- //If the Server should be stopped when the jvm exits, register
573- //with the shutdown handler thread.
572+ startupTime = ZonedDateTime .now ();
573+
574+ // If the Server should be stopped when the jvm exits,
575+ // register with the shutdown handler thread.
574576 if (getStopAtShutdown ())
575577 ShutdownThread .register (this );
576578
@@ -697,6 +699,8 @@ protected void doStop() throws Exception
697699 if (LOG .isDebugEnabled ())
698700 LOG .debug ("doStop {}" , this );
699701
702+ startupTime = null ;
703+
700704 Throwable multiException = null ;
701705
702706 if (getStopTimeout () > 0 )
0 commit comments