Greetings all
i have a j2ee app using spring framework
and while debugging on the online server (centos os)
when trying to get the date in the app by printing the value of new Date();
object
it retrieves the time in GMT-6 although when getting the server time through the terminal
command date it's retrieved in GM开发者_如何学编程T time, the real time, so i am wondering where does the GMT-6 came from, why such strange behaver occurs ?
This sounds like a locale issue to me. More specifically, it's not an issue, it's just Java's way of handling different timezone/regional settings.
Using code from this article:
Properties p = System.getProperties();
Enumeration keys = p.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
String value = (String)p.get(key);
System.out.println(key + ": " + value);
}
you can see how Java interprets your environment.
If you change CentOS' timezone/regional settings, Java should pick up that change and display time accordingly.
But that sounds like an overkill and customizing date format based on locale might be what you need.
Different applications may output the same date differently.
Perhaps somewhere in your application the default timezone is changed with TimeZone.setDefault(..)
?
Problem is solved after restarting the apache,tomcat... but still don't know why such behaviour occurs.
精彩评论