2014-11-24 21 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