-1

I have a web application run on Linux.

The date command shows below.

enter image description here

But the date in my log file is

enter image description here

The date in my log file is wrong. Why the date is different? How can I fix it? I've restarted my server but it doesn't work.

chaos
  • 1,359
  • 2
  • 13
  • 25
  • Try to get current timezone in your code. You must set the UTC time inside code the same as server UTC timezone. Ref: https://stackoverflow.com/questions/2403109/how-to-make-date-gettime-returns-utc-time – Bui Anh Tuan Sep 04 '17 at 03:02
  • I use the slf4j + log4j and my PatternLayout is `%d [%7r] %6p:%L - %c - %m \n`. I don't know how to change the timezone in log4j. Besides The date in log file was correct several days ago. – chaos Sep 04 '17 at 03:31
  • Did you try https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html ? `For example, %d{HH:mm:ss,SSS}, %d{dd MMM yyyy HH:mm:ss,SSS}, %d{DATE} or %d{HH:mm:ss}{GMT+0}` – Bui Anh Tuan Sep 04 '17 at 03:47
  • Are you (or your server) in Central America or Saskatchewan? Not many places in the world use CST at this time of year. – Ole V.V. Sep 04 '17 at 04:34
  • Do I understand correctly that the log file times are nearly 12 hours 4 minutes behind the system time? – Ole V.V. Sep 04 '17 at 04:36
  • With my question about CST I too hastily assumed (American) Central Standard Time. It could also be China Standard Time, Cuba Standard Time or even Australian Central Standard Time. – Ole V.V. Sep 04 '17 at 04:38
  • Yes, the log file times are exactly 12 hours behind the system time. – chaos Sep 05 '17 at 02:48
  • A time zone issue? Assuming CST is UTC-6, your logging framework using a zone offset of UTC-18 would explain. While there is no zone in the world using such an offset, this happens to be the minimum offset Java can work with, so I cannot rule it out completely. You may want to play around with setting the offset explicitly, as @TuanBA suggested, if you have not tried that already. – Ole V.V. Sep 05 '17 at 06:06

1 Answers1

1

Unless user specifies the timezone or uses -Duser.timezone to set the timezone to local time (in your case seems to be CST), JDK would use UTC/GMT as the timezone value by default.

Vidya
  • 11
  • 1