2014-11-24 72 views
0

在我的工作中,我们有两台linux应用服务器,都安装了websphere 6.1。我已经编写了一个简单的独立Java应用程序来打印当前时间。websphere jre timezone incorrect

public static void main(String[] args) { 
      TimeZone tz = TimeZone.getDefault(); 
      System.out.println("the default timezone is " + tz.getDisplayName(true, TimeZone.LONG)); 
      System.out.println("the default timezone ID is " + tz.getID()); 
      System.out.println("useDaylightTime = " + tz.useDaylightTime()); 
    } 

在盒子应用服务器一个我得到...

the default timezone is Eastern Summer Time (New South Wales) 
the default timezone ID is Australia/Sydney 
useDaylightTime = true 

在盒子应用服务器b我得到...

the default timezone is GMT+10:00 
the default timezone ID is GMT+10:00 
useDaylightTime = false 

我想应用服务器b相同a。有人能帮助我解决这个问题吗?

感谢

+0

你可能想看看[3种方法来改变Linux中的时区 - wikiHow](http://www.wikihow.com/Change-the-Timezone-in-Linux) – 2014-11-24 03:09:38

+0

@Paul。嗨,我不认为这是系统时间问题。当我在命令行输入日期时,时间是相同的。我认为这是一个java jre时间问题。 – Richie 2014-11-24 03:17:29

+0

您的意思是说,两台机器的**时区**是相同的? – 2014-11-24 03:19:10

回答

0

当使用getDefault()方法,如果没有缓存,Java将根据您的报告输出

Use the user.timezone property value as the default time zone ID if it's available. 
Detect the platform time zone ID. 
Use GMT as the last resort if the given or detected time zone ID is unknown. 

,看起来好像在应用程序服务器B没有用户。时区属性集。 据http://chandank.com/application-server/was/set-timezone-in-websphere-application-server,您可以设置时区按照以下步骤

1. Start the administrative console. 
2. In the topology tree, expand Servers >> Application Servers. 
3. Click on application server for which you want to set the time zone 
4. On the application server page, click Process Definition>>Java Virtual Machine>>Custom Properties>>New 
5. Specify user.timezone in the Name field and timezone in the Value field, where timezone is the supported value for your time zone. 
6. Click Apply/ok 
7. Save the configuration 


ex : Name - user.timezone 
    value - Asia/Singapore 

所以我会验证它是否正确设置你的B体系。在你的情况下,你会改变亚洲/新加坡到澳大利亚/悉尼

如果上述程序不起作用(无论什么原因),我只是通过时钟设置设置你的时区应该修复它假设你可以做到这一点。我没有可用的Websphere系统来测试它。

+0

感谢您的评论。我已经在box b上检查了websphere console for user.timezone,并且它不是作为自定义属性的。我想这意味着它是平台时区编号。但我认为它们在两个盒子上都是相同的(请参阅我对@Charlie的评论)。 – Richie 2014-11-24 03:48:40

+0

您是否可以尝试将其作为新的自定义属性添加到每个步骤4或者该选项不可用?我相信没有在那里的财产会解释这个问题,因为它会默认为GMT时间。 – 2014-11-24 04:01:40

+0

它没有在两台机器上设置,所以最初我没有尝试并设置它,但我只是试图设置它在盒子上,猜猜它是什么...它的工作!谢谢。尽管我的两个盒子还有一些区别。但没关系。感谢你的帮助 – Richie 2014-11-24 04:34:45