mridulm commented on code in PR #44613:
URL: https://github.com/apache/spark/pull/44613#discussion_r1443141156


##########
core/src/main/scala/org/apache/spark/ui/UIUtils.scala:
##########
@@ -42,15 +44,18 @@ private[spark] object UIUtils extends Logging {
   val TABLE_CLASS_STRIPED = TABLE_CLASS_NOT_STRIPED + " table-striped"
   val TABLE_CLASS_STRIPED_SORTABLE = TABLE_CLASS_STRIPED + " sortable"
 
-  // SimpleDateFormat is not thread-safe. Don't expose it to avoid improper 
use.
-  private val dateFormat = new ThreadLocal[SimpleDateFormat]() {
-    override def initialValue(): SimpleDateFormat =
-      new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US)
-  }
+  private val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd 
HH:mm:ss", Locale.US)
 
-  def formatDate(date: Date): String = dateFormat.get.format(date)
+  def formatDate(date: Date): String = {
+    val localDateTime = 
date.toInstant.atZone(java.time.ZoneId.systemDefault()).toLocalDateTime
+    localDateTime.format(dateTimeFormatter)
+  }
 
-  def formatDate(timestamp: Long): String = dateFormat.get.format(new 
Date(timestamp))
+  def formatDate(timestamp: Long): String = {
+    val localDateTime =
+      
Instant.ofEpochMilli(timestamp).atZone(java.time.ZoneId.systemDefault()).toLocalDateTime
+    localDateTime.format(dateTimeFormatter)
+  }

Review Comment:
   nit: cache `java.time.ZoneId.systemDefault()` as a field.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to