• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with SimpleDateFormat (CommandLine vs WebApp)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Use Code Tags. It will preserve your formatting.

Just to make sure, you have tried it with the command line on the same machine where the web application is running?
 
Venkata Nagendra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Rob
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Others have complained of the same date format string being rendered differently between different JVM versions: see here and here.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Where i have to download JRocket for JDK1.6 ?

Thanks

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's JRockit, not JRocket.

JRockit is not some add-on that you can download for your JDK 1.6. It is BEA's implementation of the JVM. BEA has been bought by Oracle a few years ago. I don't think that the JRockit JVM is still available at the moment.
 
reply
    Bookmark Topic Watch Topic
  • New Topic