From 87f95adc2e6c5081ad16a21e27de36cf02f605c3 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Thu, 19 Mar 2020 14:50:00 +0800 Subject: [PATCH] Fix timezone problem of sentinel-block.log Signed-off-by: Eric Zhao --- .../com/alibaba/csp/sentinel/eagleeye/FastDateFormat.java | 2 +- .../csp/sentinel/eagleeye/EagleEyeCoreUtilsTest.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/eagleeye/FastDateFormat.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/eagleeye/FastDateFormat.java index 30a7cbad..eefc6d4f 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/eagleeye/FastDateFormat.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/eagleeye/FastDateFormat.java @@ -75,7 +75,7 @@ class FastDateFormat { private SimpleDateFormat createSimpleDateFormat() { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - fmt.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); + fmt.setTimeZone(TimeZone.getDefault()); return fmt; } } diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/eagleeye/EagleEyeCoreUtilsTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/eagleeye/EagleEyeCoreUtilsTest.java index 41c8e032..f7e4f93d 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/eagleeye/EagleEyeCoreUtilsTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/eagleeye/EagleEyeCoreUtilsTest.java @@ -15,6 +15,8 @@ */ package com.alibaba.csp.sentinel.eagleeye; +import java.util.TimeZone; + import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -153,8 +155,8 @@ public class EagleEyeCoreUtilsTest { @Test public void testFormatTime() { - Assert.assertEquals("2019-06-15 20:13:14.000", - EagleEyeCoreUtils.formatTime(1560600794000L)); + Assert.assertEquals("2019-06-15 12:13:14.000", + EagleEyeCoreUtils.formatTime(1560600794000L - TimeZone.getDefault().getRawOffset())); } @Test