Forum Stats

  • 3,875,792 Users
  • 2,266,972 Discussions
  • 7,912,341 Comments

Discussions

Problem with SimpleDateFormat (CommandLine vs WebApp)

392220
392220 Member Posts: 12
edited Oct 7, 2008 6:08PM in WebLogic Portal
Hello Friends,

I have a strange problem. Not sure what is the mistake from my side. I have simple class that returns formatted date based on TimeZone. It gives me different result if run on command line vs when used in web app (weblogic portal app). Below is the code & other information.

import java.util.*;
import java.text.*;

public class Test {

public static String getDateFormatted(String tZone) {
DateFormat dfm = new SimpleDateFormat("dd-MMMM-yyyy HH:mm:ss z");
dfm.setTimeZone(TimeZone.getTimeZone(tZone));
return dfm.format(new Date());
}

public static void main(String ar[]) {
System.out.println(getDateFormatted(ar[0]));
}

}

Output From Command Prompt
java Test PST
06-October-2008 20:37:01 PDT


Output From webapp running on Weblogic Server Version 10.0
06-October-2008 23:37:04 GMT-04:00


Java version from my command prompt
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)


To confirm if this problem is due to JRockit that is used as default for Weblogic, I changed Java Home in setDomainEnv.cmd to Sun JDK. But still no luck.

set BEA_JAVA_HOME=C:\bea\jrockit_150_11

set SUN_JAVA_HOME=C:\bea\jdk150_11

if "%JAVA_VENDOR%"=="BEA" (
set JAVA_HOME=%SUN_JAVA_HOME%
) else (
if "%JAVA_VENDOR%"=="Sun" (
set JAVA_HOME=%SUN_JAVA_HOME%
) else (
set JAVA_VENDOR=Sun
set JAVA_HOME=C:\bea\jdk150_11
)
)

Thanks & Appreciate any suggestions

Answers

  • 655221
    655221 Member Posts: 116
    Maybe you could eliminate the locale as a suspect by testing with a hard-coded Locale instance by using the SimpleDateFormat constructor that takes a Locale arg:

    http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html#SimpleDateFormat(java.lang.String,%20java.util.Locale)

    ???
This discussion has been closed.