BUG IN SimpleDateFormat ?

hi all,
i want to get the difference between 2 dates (time), so i use the following code:
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("hh:mm:ss");
String time1 = "12:48:10";
String time2 = "12:48:09";
Date date1 = format.parse(time1);
Date date2 = format.parse(time2);
lTotalTime = date1.getTime() - date2.getTime();
System.out.println( "Time diff :" + format.format(new Date(lTotalTime)));
but the result is ==> Time diff :01:00:01
why do i get 1 hour too much????
the result should be 00:00:01
any idea what goes wrong?
thanx,
andi

Hi!
try the following, and u will see, it's ok!
import java.util.*;
public class Test
public static void main(String[] args)
try
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("hh:mm:ss");
java.text.SimpleDateFormat formatlong = new java.text.SimpleDateFormat("dd.MM.yyyy hh:mm:ss");
String time1 = "12:48:10";
String time2 = "12:48:09";
Date date1 = format.parse(time1);
Date date2 = format.parse(time2);
long lTotalTime = date1.getTime() - date2.getTime();
System.out.println( "Time1: " + time1 +
" " + date1.getTime() +
" " + formatlong.format(new Date(date1.getTime())));
System.out.println( "Time2: " + time2 +
" " + date2.getTime() +
" " + formatlong.format(new Date(date2.getTime())));
System.out.println( "Time diff long: " + lTotalTime);
System.out.println( "Time diff: " + format.format(new Date(lTotalTime)));
System.out.println( "Time zero: " + format.format(new Date(0)));
catch (Throwable thr) {thr.printStackTrace();}
result:
Time1: 12:48:10 -710000 01.01.1970 12:48:10
Time2: 12:48:09 -711000 01.01.1970 12:48:09
Time diff long: 1000
Time diff: 01:00:01
Time zero: 01:00:00
The time difference is 1000 milliseconds, and this is right!
The only problem here is, that a Date initialized with zero is 01:00:00!
So you get the right difference to this date!
regards,
Martin

Similar Messages

  • I just run into an anoying little bug with SimpleDateFormat......

    Try run this code:
    Filename: Foo.java
    import java.util.*;
    import java.text.*;
    public class Foo {
      public static void main(String args[]) {
        DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
        Date date = null;
        try {
          date = df.parse("31.12.2002");
        } catch (Exception e) {
          e.printStackTrace();
        System.out.println("Date initiated: "+date.toString());
        df = new SimpleDateFormat("yyyy-ww");
        System.out.println("Week expected is 2003-01");
        System.out.println("Rendered week : "+df.format(date));
    End of file
    Output from code:
    H:\>java Foo
    Date initiated: Tue Dec 31 00:00:00 CET 2002
    Week expected is 2003-01
    Rendered week : 2002-01
    Anyone know any workaround to get the expected result?
    I am sitting on a DW project that has met this anoying little bug, and I have posted this to the bug parade aswell, but I have no time to wait for a new release of the JDK :) Hope you can help
    My os:
    Windows 2000 SP 2
    My JDK version (cannot use 1.4):
    java version "1.3.1_04"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_04-b02)
    Java HotSpot(TM) Client VM (build 1.3.1_04-b02, mixed mode)
    Any help is appreciated.

    As Sun says, calculations using Date are ok for computers. but if you need to do things that people want to do with dates, use Calendar/GregorianCalendar. Here's a couple of examples
    import java.util.*;
    import java.text.*;
    public class Calendar2 {
        public static void main(String[] args) {
            Calendar cal = Calendar.getInstance(); // today as Calendar obj;
            cal.add(cal.MONTH, 6);
            // change to Date object for better format control;
            Date sixMonthsFromNow = cal.getTime();
            // create custom format;
            DateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
            // apply format and print;
            System.out.println(sdf.format(sixMonthsFromNow));
    import java.util.*;
    public class Calendar1 {
        public static void main(String[] args) {
            Calendar cal = Calendar.getInstance();
            for( int n = 0; n < 7; n++ ) {
                    System.out.println(cal.get(cal.DATE) + "/" + (cal.get(cal.MONTH) + 1) + "/" + cal.get(cal.YEAR));
                    cal.add(cal.DATE, 1);
    }

  • Possible SimpleDateFormat.parse(...) error.

    Consider this code segment
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
    String testDate[] = {
                   "2005-07-29 16:28:38.83",
                   "2005-07-29 16:28:38.003",
                   "2005-07-29 16:28:38.03",
                   "2005-07-29 16:28:38.3"
              for (int i = 0; i < testDate.length; i++)
                   Timestamp date = Timestamp.valueOf(testDate);
                   Date utilDate = sdf.parse(testDate[i]);     
                   System.out.println(testDate[i] + " : "+(date.getTime()+date.getNanos()/1000000)+" : "+utilDate.getTime());
    Output is:
    2005-07-29 16:28:38.83 : 1122668918830 : 1122668918083
    2005-07-29 16:28:38.30 : 1122668918300 : 1122668918030
    2005-07-29 16:28:38.003 : 1122668918003 : 1122668918003
    2005-07-29 16:28:38.03 : 1122668918030 : 1122668918003
    2005-07-29 16:28:38.3 : 1122668918300 : 1122668918003
    Now if we look at msecs portion, sdf.parse is parsing .3 and .03 and .003 as 003
    But Timestamp is parsing in right way. .3 = 300, .03 = 030 and .003 = 003
    I tested this program with ibm jdk 1.3 and sun jdk 1.5 with same results.
    Is it known bug of simpleDateFormat or some unknown feature?
    Thanks
    Ashish

    Thanks to reply!!
    It makes sense for SimpleDateFormat to behave this way.
    I was wondering, if i can retrieve millisecs portion with trailing zeros.. instead of padded zeros. Any setting in SimpleDateFormat?
    One way, I am experimenting is Timestamp.valueOf()
    Thanks
    Ashish

  • Problem in starting Weblogic 5.1 with Solaris 2.6

    Hi all:
    I am getting the following errors when I run Weblogic 5.1 on Solaris 2.6. I
    am going to the prompt and
    executing startWebLogic.sh command. Do we have to write a KSH for this. I am getting
    the following errors.My first question is that do we need
    Java version 1.2 or above to execute WLS5.1. My license file has the valid license
    entries in the file. Please go
    through it and give me suggestions.
    My License file entries:
    <WEBLOGIC-LICENSES>
    <LICENSE PRODUCT="WebLogic"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="1d3c1f482515f5b4bbf4639c86564e3a"
    />
    <LICENSE PRODUCT="WebLogic/SSL"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="8952273c8d5ffcd568c0092bc95faf05"
    />
    <LICENSE PRODUCT="WebLogic/ClusterII"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="4c607083770e6f917ea719a888499b68"
    />
    <LICENSE PRODUCT="jdbcKona/Oracle"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="8025e0ee6e6e301a03714f2e949c93a8"
    />
    <LICENSE PRODUCT="jdbcKona/Sybase"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="aa680dc79bee2b67645e1a9b602092c2"
    />
    <LICENSE PRODUCT="jdbcKona/MSSQLServer4"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="7fd41a5a9f51f79e491d1a901ad5f04c"
    />
    <LICENSE PRODUCT="jdbcKona/Informix4"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="7a5992e6f46cb94b13041d7d2992c0bb"
    />
    <LICENSE PRODUCT="jdbcKona/MSSQLServer"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="7ae6465612751853e942286a2fff2182"
    />
    </WEBLOGIC-LICENSES>
    <!--^M
    Copyright (c) 1997-1999 by BEA Systems, Inc. All Rights Reserved.^M
    ^M
    WebLogicLicense.xml^M
    ^M
    This is your WebLogic license file.^M
    ^M
    Prior to evalating the WebLogic products, you must first read and^M
    accept the evaluation license at:^M
    ^M
    http://www.weblogic.com/licbeta.html^M
    ^M
    and register as an evaluation user. ^M
    ^M
    When you purchase a product license for WebLogic, you will^M
    receive non-expiring keys for this file by email.^M
    ^M
    Instructions on how to edit and compile this file are online in the^M
    WebLogic Administrator Guide "Installing a WebLogic license" at:^M
    ^M
    http://www.weblogic.com/docs/techstart/license.html^M
    ^M
    If you have other questions about this file or obtaining license^M
    keys, you can email us at [email protected].^M
    -->^M
    <!-- Keys for version 4.0 and later -->^M
    <WEBLOGIC-LICENSES>^M
    <LICENSE PRODUCT="WebLogic"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="faebf1221509b2736dfaeb5c44888cd0"^M
    />^M
    <LICENSE PRODUCT="WebLogic/SSL"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="265850b96d6968031ae89006ee67eaae"^M
    />^M
    <LICENSE PRODUCT="Personalization"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="7a066dc751368d3ed7f6a4814d4e503d"^M
    />^M
    <LICENSE PRODUCT="WebLogic/ClusterII"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="7727113940ad9e437a5b53ac91cfe10e"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/Oracle"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="ece7c023669fa3acf4e071972a917299"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/Sybase"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="db0a96966b5991110b522fb8a1a9a187"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/MSSQLServer4"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="cade68cb4c93b1a58cb9fc27233dc872"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/Informix4"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="b1147046c1cb4d2fc50161ed4000075d"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/MSSQLServer"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="d3d6d957274aa5492adab8224ef0b468"^M
    />^M
    </WEBLOGIC-LICENSES>^M
    Errors:
    LD_LIBRARY_PATH=/export/opt/weblogic/weblogic/lib/solaris
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0 ?
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0 ?
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0 ?
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0 ?
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0 ?
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0 ?
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0 ?
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0 ?
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0 ?
    SimpleDateFormat produced: 07-Dec-2000 but should equal: 08-Dec-2000 Note that
    older java runtime versions had a bug in SimpleDateFormat...
    SimpleDateFormat produced: 07-Dec-2000 but should equal: 08-Dec-2000 Note that
    older java runtime versions had a bug in SimpleDateFormat...
    $$$$$$$$$$$$$$$$ License Exception $$$$$$$$$$$$$$$$
    Loaded License : /export/opt/weblogic/weblogic/license/WebLogicLicense.xml
    However Unable to start because :
    License key incorrect for WebLogic,any,3,07-Dec-2000|faebf1221509b2736dfaeb5c448
    88cd0
    As well as the fact that: No License found for Tengah
    As well as the fact that: No License found for WebLogic/JDBC
    As well as the fact that: No License found for Tengah/JDBC
    As well as the fact that: No License found for jdbcKona/T3

    1) Remove the second section in your license file that contains
    expired licenses.
    2) Check the Supported Platforms page for what JDK you should
    use.
    Mike
    "Hari Pillai" <[email protected]> wrote:
    >
    Hi all:
    I am getting the following errors when I run Weblogic 5.1 on Solaris
    2.6. I
    am going to the prompt and
    executing startWebLogic.sh command. Do we have to write a KSH for this.
    I am getting
    the following errors.My first question is that do we need
    Java version 1.2 or above to execute WLS5.1. My license file has the
    valid license
    entries in the file. Please go
    through it and give me suggestions.
    My License file entries:
    <WEBLOGIC-LICENSES>
    <LICENSE PRODUCT="WebLogic"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="1d3c1f482515f5b4bbf4639c86564e3a"
    />
    <LICENSE PRODUCT="WebLogic/SSL"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="8952273c8d5ffcd568c0092bc95faf05"
    />
    <LICENSE PRODUCT="WebLogic/ClusterII"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="4c607083770e6f917ea719a888499b68"
    />
    <LICENSE PRODUCT="jdbcKona/Oracle"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="8025e0ee6e6e301a03714f2e949c93a8"
    />
    <LICENSE PRODUCT="jdbcKona/Sybase"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="aa680dc79bee2b67645e1a9b602092c2"
    />
    <LICENSE PRODUCT="jdbcKona/MSSQLServer4"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="7fd41a5a9f51f79e491d1a901ad5f04c"
    />
    <LICENSE PRODUCT="jdbcKona/Informix4"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="7a5992e6f46cb94b13041d7d2992c0bb"
    />
    <LICENSE PRODUCT="jdbcKona/MSSQLServer"
    IP="161.127.67.35" UNITS="4" EXPIRATION="never"
    KEY="7ae6465612751853e942286a2fff2182"
    />
    </WEBLOGIC-LICENSES>
    <!--^M
    Copyright (c) 1997-1999 by BEA Systems, Inc. All Rights Reserved.^M
    ^M
    WebLogicLicense.xml^M
    ^M
    This is your WebLogic license file.^M
    ^M
    Prior to evalating the WebLogic products, you must first read and^M
    accept the evaluation license at:^M
    ^M
    http://www.weblogic.com/licbeta.html^M
    ^M
    and register as an evaluation user. ^M
    ^M
    When you purchase a product license for WebLogic, you will^M
    receive non-expiring keys for this file by email.^M
    ^M
    Instructions on how to edit and compile this file are online in the^M
    WebLogic Administrator Guide "Installing a WebLogic license" at:^M
    ^M
    http://www.weblogic.com/docs/techstart/license.html^M
    ^M
    If you have other questions about this file or obtaining license^M
    keys, you can email us at [email protected].^M
    -->^M
    <!-- Keys for version 4.0 and later -->^M
    <WEBLOGIC-LICENSES>^M
    <LICENSE PRODUCT="WebLogic"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="faebf1221509b2736dfaeb5c44888cd0"^M
    />^M
    <LICENSE PRODUCT="WebLogic/SSL"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="265850b96d6968031ae89006ee67eaae"^M
    />^M
    <LICENSE PRODUCT="Personalization"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="7a066dc751368d3ed7f6a4814d4e503d"^M
    />^M
    <LICENSE PRODUCT="WebLogic/ClusterII"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="7727113940ad9e437a5b53ac91cfe10e"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/Oracle"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="ece7c023669fa3acf4e071972a917299"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/Sybase"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="db0a96966b5991110b522fb8a1a9a187"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/MSSQLServer4"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="cade68cb4c93b1a58cb9fc27233dc872"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/Informix4"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="b1147046c1cb4d2fc50161ed4000075d"^M
    />^M
    <LICENSE PRODUCT="jdbcKona/MSSQLServer"^M
    IP="any" UNITS="3" EXPIRATION="08-Dec-2000"^M
    KEY="d3d6d957274aa5492adab8224ef0b468"^M
    />^M
    </WEBLOGIC-LICENSES>^M
    Errors:
    LD_LIBRARY_PATH=/export/opt/weblogic/weblogic/lib/solaris
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have
    produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have
    produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have
    produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have
    produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have
    produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have
    produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have
    produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have
    produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0
    SimpleDateFormat produced: Fri Dec 08 03:00:00 EST 2000 but should have
    produced
    : Fri Dec 08 00:00:00 EST 2000. Is your java runtime older than 1.2.0
    SimpleDateFormat produced: 07-Dec-2000 but should equal: 08-Dec-2000
    Note that
    older java runtime versions had a bug in SimpleDateFormat...
    SimpleDateFormat produced: 07-Dec-2000 but should equal: 08-Dec-2000
    Note that
    older java runtime versions had a bug in SimpleDateFormat...
    $$$$$$$$$$$$$$$$ License Exception $$$$$$$$$$$$$$$$
    Loaded License : /export/opt/weblogic/weblogic/license/WebLogicLicense.xml
    However Unable to start because :
    License key incorrect for WebLogic,any,3,07-Dec-2000|faebf1221509b2736dfaeb5c448
    88cd0
    As well as the fact that: No License found for Tengah
    As well as the fact that: No License found for WebLogic/JDBC
    As well as the fact that: No License found for Tengah/JDBC
    As well as the fact that: No License found for jdbcKona/T3

  • A bug in the SimpleDateFormat ?

    When i parse the string "2089-03-28" with the SimpleDateFormat class, the result's timeZone change from CET to CEST...
    There is a difference of 1 hour between the two timeZone. So i'm not able to (exactly) compute the difference (in day) between two date.
    why? is it a bug ?
    Here is the code :
    s1 = "2089-03-27";
    s2 = "2089-03-28";
    sdf = new SimpleDateFormat("yyyy-MM-dd");
    d1 = sdf.parse(s1);
    d2 = sdf.parse(s2);
    System.out.println(s1 + " -> " + d1.toString() + " -> " + d1.getTime());
    System.out.println(s2 + " -> " + d2.toString() + " -> " + d2.getTime());
    diff = (d2.getTime() - d1.getTime());
    div = 24 * 60 * 60 * 1000; // # number of ms in a day
    res = diff / div; // give me the number of day between the two date
    System.out.println(diff + " / " + div + " = " + res);
    System.out.println(diff + " - " + div + " = " + (diff-div));here is the result :
    2089-03-27 -> Sun Mar 27 00:00:00 CET 2089 -> 3762716400000
    2089-03-28 -> Mon Mar 28 00:00:00 CEST 2089 -> 3762799200000
    8.28E7 / 8.64E7 = 0.9583333333333334
    8.28E7 - 8.64E7 = -3600000.0i used a little workaround. So i did my job correctly but i wish to known what the SimpleDAteFormat do...
    Thanks for any help.

    i try with another date between 200-01-01 and
    2089-03-27 and it always work!
    It seems that SimpleDateFormat don't like the date
    "2089-03-28". Why? I want to know... ;-)You were given the answer. What was confusing about the replies you received?

  • SimpleDateFormat bug?

    The code at the end throws this exception:
    java.text.ParseException: Unparseable date: "Wed Jul 16 10:37:52 2003"
         at java.text.DateFormat.parse(DateFormat.java:334)
         at pruebas.prueba.main(prueba.java:31)
    It's thrown when the SimpledateFormat object is going to be parsed. If I delete 'EEE' from the pattern and 'Web' from the 'fullFecha' string it works fine. I don't know if I'm doing something wrong or if this is a SimpleDateFormat class bug. Please, help!
    public class prueba
    public static void main(String[] args)
    String datePattern = new String ("EEE MMM d HH:mm:ss yyyy");
    SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern);
    DateFormat df = dateFormat.getDateInstance();
    Date fecha = null;
    String fullFecha = new String("Wed Jul 16 10:37:52 2003");
    try
    fecha = dateFormat.parse(fullFecha);
    System.out.println(fecha.getTime());
    System.out.println(fecha.toString());
    } catch (Exception e)
    e.printStackTrace();

    I think Abelhinha is right it probably has to do with your locale,
    to check run the following code:
    System.out.println(System.getProperty("user.language"));
    System.out.println(System.getProperty("user.country"));This will tell you what language you are running, as well as
    what country you are set up for.
    -Philip

  • Is this a SimpleDateFormat bug?

    Hello to all.
    Consider a SimpleDateFormar with a pattern: "dd-MM-yyyy"
    I think the string "01-01-2010mwwwwwwwwwwwwwww" does not satisfy the pattern, but the following code shows the contrary.
    Anyone can explain why?
    public static void main(String[] args) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        Date date = df.parse("01-01-2010mwwwwwwwwwwwwwww");
        System.out.println(date);
    }Thanks

    paulcw wrote:
    There might be another way to do this (confirm that a string contains a valid date and only a valid date), but I don't know what it is.That would be the parse(String, ParsePosition) method (check the API docs). Give it a ParsePosition object which says "Start at the first position", then call the method. When it returns it will have updated the ParsePosition object; you can look at that to see if the current position is past the end of the String, or whatever.
    Pretty clunky, really, but I guess when you work with the Date and Calendar class your mind becomes poisoned and you find yourself producing more weird designs like this one.

  • WEEK_OF_MONTH parsing in SimpleDateFormat

    Hello,
    I am trying to use the WEEK_OF_MONTH (capital W) in SimpleDateFormat. I want to be able to do both parse() and format() of in the format "yyMMWW". I also want to use false lenient in order to have strict control.
    I have seen that the first week every month (WEEK_OF_MONTH == 1) can not be parsed properly. Below is an example program demonstrating the issue.
    The program tries 100 dates from Jan 1 2006 and onwards. It converts to the yyMMWW format (which always goes fine). I also try to convert back from the yyMMWW format (using parse() method) and see that it fails on some dates.
    I get an parse exception like this:
    060204 -> 060201 -> java.text.ParseException: Unparseable date: "060201"
    060205 -> 060201 -> java.text.ParseException: Unparseable date: "060201"
    060206 -> 060202 -> 060206
    060207 -> 060202 -> 060206
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;
    public class SimpleDateFormatIssue {
         public static void main(String[] args) throws ParseException {
              GregorianCalendar cal = new GregorianCalendar();
              cal.setFirstDayOfWeek(Calendar.MONDAY);
              cal.setLenient(false); //Strict checkin, significant for the issue
              //System.out.println(cal.getMinimalDaysInFirstWeek()); //doesnt matter what
              SimpleDateFormat fYYMMDD = new SimpleDateFormat("yyMMdd");
              fYYMMDD.setCalendar(cal);
              SimpleDateFormat fYYMMWW = new SimpleDateFormat("yyMMWW");
              fYYMMWW.setCalendar(cal);
              Date d = fYYMMDD.parse("060101");
              for (int i = 0; i < 100; i++) {
                   String outputYYMMWW = fYYMMWW.format(d);
                   Date parsedYYMMWW = null;
                   Exception exc = null;
                   try {
                        parsedYYMMWW = fYYMMWW.parse(outputYYMMWW);
                   } catch (ParseException e) {
                        exc = e;
                   System.out.println(fYYMMDD.format(d) + " -> " + outputYYMMWW + " -> " + (parsedYYMMWW != null ? fYYMMDD.format(parsedYYMMWW) : exc));
                   d = getDayAfter(cal,d);
         public static Date getDayAfter(Calendar cal, Date date) {
              cal.setTime(date);
              cal.add(Calendar.DAY_OF_MONTH,1);
              Date dayAfter = cal.getTime();
              return dayAfter;
    So I wonder, am I doing SimpleDateFormat abuse when I want to parse a yyMMWW formated string?
    Or perhaps I have a bug in my program... :)
    I saw some bugs in bug parade about SimpleDateFormat and WEEK_IN_MONTH but they all appears to be fixed in Java 5 which I am using:
    java -version
    java version "1.5.0_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
    Thank you in advance for any pointers.
    /Anders

    The ones that fail are the ones before the first Monday of the month (since you set Monday as the first day of the week). So, I guess saying you are in the first week "060201" can't be translated back to a Monday in February.
    Not sure what to do about it, though. (I didn't look what, if anything, any bugs said about it.)

  • BUG: Warning/Error just refreshing page several times???

    Hi!
    I made a simple page:
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
              xmlns:dvt="http://xmlns.oracle.com/dss/adf/faces">
      <jsp:directive.page contentType="text/html;charset=UTF-8"/>
      <f:view>
        <af:document>
          <af:messages/>
          <af:form>
            <af:pageTemplate viewId="/oracle/templates/threeColumnTemplate.jspx">
              <f:facet name="center">
                <af:panelGroupLayout layout="vertical">
                  <af:subform>
                    <dvt:graph graphType="LINE_VERT_ABS"
                               dynamicResize="DYNAMIC_SIZE"
                               value="#{bindings.SampleGraphDataRow.graphModel}"/>
                    <af:commandButton text="commandButton 1"/>
                  </af:subform>
                </af:panelGroupLayout>
              </f:facet>
              <f:facet name="header"/>
              <f:facet name="end"/>
              <f:facet name="start"/>
              <f:facet name="branding"/>
              <f:facet name="copyright"/>
              <f:facet name="status"/>
            </af:pageTemplate>
          </af:form>
        </af:document>
      </f:view>
    </jsp:root>First time I get a page without any problems (expect standard "WARNING: Header modification request was rejected. Because the setter method was called from included servlet. It is restricted by SRV.8.3 of Servlet Specification 2.4. : current-workspace-app" I'm getting with every single page).
    Then I was just refreshing this page a few times (clicking a refresh button in browser, without doing anything else in page – so no PPRs, actions etc. – so no client events should be produced by my acting beside page refresh).
    After several refreshes, strange WARNING (looking more like error than just warning) appeared in log window:
    WARNING: empty String
    java.lang.NumberFormatException: empty String
         at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
         at java.lang.Double.parseDouble(Double.java:510)
         at java.text.DigitList.getDouble(DigitList.java:151)
         at java.text.DecimalFormat.parse(DecimalFormat.java:1303)
         at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1918)
         at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1264)
         at java.text.DateFormat.parse(DateFormat.java:335)
         at com.evermind.server.http.EvermindHttpServletRequest.getDateHeader(EvermindHttpServletRequest.java:1581)
         at com.evermind.server.http.EvermindHttpServletRequest.getDateHeader(EvermindHttpServletRequest.java:1379)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         at org.apache.myfaces.trinidad.webapp.ResourceServlet.service(ResourceServlet.java:162)
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
         at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:118)
         at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
         at oracle.security.jazn.oc4j.JAZNFilter$3.run(JAZNFilter.java:434)
         at java.security.AccessController.doPrivileged(Native Method)
         at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:308)
         at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:452)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:583)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:334)
         at com.evermind.server.http.HttpRequestHandler.doDispatchRequest(HttpRequestHandler.java:942)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:843)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:658)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:626)
         at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:417)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:189)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:163)
         at oracle.oc4j.network.ServerSocketReadHandler$ClientRunnable.run(ServerSocketReadHandler.java:275)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
         at java.lang.Thread.run(Thread.java:619)
    May 11, 2008 8:16:21 PM com.evermind.server.ServerBase log
    WARNING: Application1-ViewController-webapp: Servlet error
    oracle.security.jazn.JAZNRuntimeException: empty String
         at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:480)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:583)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:334)
         at com.evermind.server.http.HttpRequestHandler.doDispatchRequest(HttpRequestHandler.java:942)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:843)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:658)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:626)
         at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:417)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:189)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:163)
         at oracle.oc4j.network.ServerSocketReadHandler$ClientRunnable.run(ServerSocketReadHandler.java:275)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.NumberFormatException: empty String
         at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
    Why is this happening? The page renders (apparently) normally, the graph renders as it should, but I'm not sure if the page is going to work correctly because of this warning/error.
    I'm using TP4 on Vista x86, with JDK 1.6u5.
    Anyone, please take a look at this. It may be a bug somewhere...
    Regards,
    PaKo

    Pako,
    the message "java.lang.NumberFormatException: empty String" points to a missing data value. I'll file a bug and ask QA to verify this.
    Frank

  • Bug on the property "disabledDays" of the component af|inputDate ?

    Hi,
    I think there is a bug on the property "disabledDays" of the component af|inputDate :
    <af:inputDate disabledDays="#{MyInputDate.disabledDays}"
    public class MyInputDate {     
        public DateListProvider getDisabledDays() {
            return new DateListProvider() {
                public List<java.util.Date> getDateList(FacesContext pFacesContext, Calendar pCalendar, java.util.Date pDate, java.util.Date pDate1) {
                    List<java.util.Date> my_array = new ArrayList<java.util.Date>();
                    try {
                        my_array.add(new SimpleDateFormat("MM/dd/yyyy").parse("1/1/2012"));
                    } catch (Exception e) {
                    return my_array;
    Problem:      While Only the 1 January 2012 cannot be selected, December 1, 2011 cannot be selected too !
    It's the same for every first day of each month...
    So, if it's possible, how can i use this property without this bug ?
    I use Oracle JDeveloper 11g Release 1 (11.1.1.4.0).

    Hi,
    the issue indeed reproduces. The fix however is pretty simple
        public List<Date> getDateList(FacesContext facesContext, Calendar calendar, Date startDate, Date endDate) {
            ArrayList<Date> l = new ArrayList<Date>();
            Date d;
            try {
                d = new SimpleDateFormat("MM/dd/yyyy").parse("01/01/2012");
                if (endDate.compareTo(d)< 0){
                    //ignore setting
                else{
                    l.add(d);
            } catch (ParseException e) {
                    e.printStackTrace();
            return l;
        }Just check if the date you set is earlier than the min range of the actual date display. If it is, don't set it as it is of no use anyway
    Frank
    Ps.: Bug filed

  • Question concerning SimpleDateFormat returning week information

    Hello,
    I am just trying to get returned a date value with the format 'ww/yyyy' and experience problems in getting the correct value around the turn of the year.
    Example:
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("w/yyyy");
    df.getCalendar().setFirstDayOfWeek(java.util.Calendar.MONDAY);
    df.getCalendar().setMinimalDaysInFirstWeek(4);
    System.out.println(df.format(new java.sql.Date(103,11,31))); //Dez, 31, 2003As output I get "01/2003" which is not correct - I expected "01/2004" instead.
    How do I get the correct output?
    Do I have miscoded there something or is this a bug?
    BTW: when trying the same with Jan, 1, 2004 I get the correct output.
    Thank you for any answers
    Ralf

    From the API documentation for java.util.Calendar:
    "The first week of a month or year is defined as the earliest seven day period beginning on getFirstDayOfWeek() and containing at least getMinimalDaysInFirstWeek() days of that month or year."
    So, since December 31 2003 was on a Wednesday and you've defined your weeks to start on Monday, there were 3 days of 2003 and 4 days of 2004 in the week containing that date. And since your "minimal days in first week" is defined to be 4, this week is the first week of 2004. In other words, its week number is 1.
    So that's why you see week number 1. (A week has only one week number.)
    And since December 31 2003 was in 2003, you see 2003 for the year.
    If you experiment a bit more with GregorianCalendar and callcal.get(Calendar.WEEK_OF_YEAR)for various dates, you should see what is going on.
    If you want the "correct" output (in other words the output you want to see, whatever it is) then you can subclass GregorianCalendar and override its get method.

  • Bug: JWS App won't start offline

    Hello,
    I have specified <offline-allowed/>, and if the client can not connect via TCP it works as expected.
    However, if the client connects to the JnlpDownloadServlet - which never responds sometimes because of bugs - the client hangs forever.
    The bug is that the JWS launcher never sets the socket read timeout. I wonder if it also sets the connect timeout. Because of the bugs in the JnlpDownloadServlet, this is a critical problem.
    Cheers.

    OK - this seems to be happening to me on a regular basis now. I have caught the bug in action with a kill -3 so Sun can see the exact line where the bug is in the JnlpDownloadServlet:
    The stack trace (from kill -3) shows the JnlpDownloadServlet stuck in SimpleDateFormat during a JWS scanDirectory(ResourceCatalog.java:281).
    It is stuck on this exact line forever. The major problem with this is:
    *** Tomcat accept()s connections successfully, and the JWS client locks forever waiting for some sort of response. Perhaps if there was a socket read timeout set the client would be able to continue after the timeout (a 5 second timeout (or configurable) would be nice).
    "Thread-4" daemon prio=1 tid=0x081db610 nid=0x58ec waiting on condition [54602000..54603854]
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:782)
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:775)
    at java.text.DateFormat.format(DateFormat.java:314)
    at java.util.Date.toString(Date.java:987)
    - locked <0x45b5d8a0> (a java.text.SimpleDateFormat)
    at java.lang.String.valueOf(String.java:2131)
    at java.lang.StringBuffer.append(StringBuffer.java:370)
    - locked <0x44840288> (a java.lang.StringBuffer)
    at com.sun.javaws.servlet.JnlpResource.toString(JnlpResource.java:142)
    at java.lang.String.valueOf(String.java:2131)
    at java.lang.StringBuffer.append(StringBuffer.java:370)
    - locked <0x44840218> (a java.lang.StringBuffer)
    at com.sun.javaws.servlet.ResourceCatalog.scanDirectory(ResourceCatalog.java:281)
    at com.sun.javaws.servlet.ResourceCatalog.lookupResource(ResourceCatalog.java:87)
    at com.sun.javaws.servlet.JnlpDownloadServlet.handleVersionRequest(JnlpDownloadServlet.java:120)
    at com.sun.javaws.servlet.JnlpDownloadServlet.locateResource(JnlpDownloadServlet.java:141)
    at com.sun.javaws.servlet.JnlpDownloadServlet.handleRequest(JnlpDownloadServlet.java:94)
    at com.sun.javaws.servlet.JnlpDownloadServlet.doGet(JnlpDownloadServlet.java:50)
    at javax.servlet.http.HttpServlet.doHead(HttpServlet.java:313)

  • SimpleDateFormat can parse 2009102x

    Hello,
    If you look to the piece of code below, it seems my users can enter 2009102w.
    However, when one tries to enter 20091w20, it throws an error.
    I don't understand why an incorrect character in my date can get my date parsed?!
    Is this a bug or is there a reason?
              try {
                      DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
                      //this is ok
                      //Date date = (Date)formatter.parse("20091020");
                      //this is also ok !!!!!
                      //Date date = (Date)formatter.parse("2009102w");
                      //this is not ok
                      //Date date = (Date)formatter.parse("20091w20");
                      System.out.println(date);
                  } catch (ParseException e) {
                       System.out.println("exception");
                  }Thanks

    The date formatter doesn't feel the need to parse all the characters you give it. If it reads an acceptable date it will ignore any garbage following. The Formatter objects in java.text seem to have been designed to parse a string with multiple elements, dates, numbers, etc., each taking it's own chunk. You'll find the same with the NumberFormat objects.
    Also, by default, the parsing mode on the data formatter is set to "lenient". If you want to tighten it up call setLenient(false) on the formatter. This is mostly about things like if you put 31/02/2009 then with lenient on you'll get 03/03/2009, but may affect the acceptance of a single digit day.
    P.S. if you really want to be strict about validating the format then check with a regexp first.
    Edited by: malcolmmc on Sep 8, 2009 8:59 AM

  • BUG??? Overridden prepareModel not being called all the time

    I have an ADF/struts application that was originally developed with Jdev 10.1.2. I then migrated it to 10.1.3 and have been maintaining it with that for that past two months. Recently, I added some new pages and in those new pages I need to do some preprocessing. I was hoping to do this in the prepareModel of this page, however it is not being called when I come to the page via a submit button that is named "event_Calendar". If I click the search button on the Calendar page though, the prepareModel does fire, and the preprocessing takes place.
    Hyperlinks do work though. If I use a html:link with page "browseCalendar.do" it does get called an the preprocessing goes perfectly. I am guessing that this does not use the framework as extensively as the above example though.
    Is this a bug?? Or am I doing something wrong??
    Let me know if you need more info.
    Thanks,
    Chris

    public class BrowseCalendarPageController extends PageController {
        public void prepareModel(LifecycleContext context)
            super.prepareModel(context);
            System.out.println("Inside prepareModel");
            StrutsPageLifecycleContext actionContext = (StrutsPageLifecycleContext)context;
            DCIteratorBinding it = actionContext.getBindingContext().findBindingContainer("browseCalendarPageDef").findIteratorBinding("BS_CalendarFindViewIterator");
            Row row = it.getViewCriteria().getCurrentRow();
            if(row.getAttribute("StartTime") == null) {
                System.out.println("StartTime is null");
                Date date = new Date();
                SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss a");
                row.setAttribute("StartTime",df.format(date));
            if(row.getAttribute("EndTime") == null) {
                System.out.println("EndTime is null");
                String start = row.getAttribute("StartTime").toString();
                SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss a");
                try{
                    Date date = df.parse(start);
                    Calendar ca = Calendar.getInstance();
                    ca.setTime(date);
                    ca.add(Calendar.DAY_OF_MONTH,7);
                    Date newDate = ca.getTime();
                    row.setAttribute("EndTime",df.format(newDate));
                catch(Exception e) {
                    e.printStackTrace();
            it.getViewObject().applyViewCriteria(it.getViewCriteria());
            it.executeQuery();
    }

  • Does SimpleDateFormat still have Thread Safety Issue in jdk 1.4.2_8?

    Hi,
    We are using jdk1.4.2_08 and experience following error message intermittently, sometimes once in 5000 or 10000 or 2/3 times in 20000 message processing.
    On one occassion, it reported as Empty String and other time it reported as ".20042005E200420054E". I won't suspect the input that's coming to this class since it works with same message over and over.
    2005-07-18 19:13:54,733 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): java.lang.NumberFormatException: empty String
    2005-07-18 19:13:54,740 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
    2005-07-18 19:13:54,745 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.lang.Double.parseDouble(Double.java:220)
    2005-07-18 19:13:54,751 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.DigitList.getDouble(DigitList.java:127)
    2005-07-18 19:13:54,756 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.DecimalFormat.parse(DecimalFormat.java:1070)
    2005-07-18 19:13:54,761 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1705)
    2005-07-18 19:13:54,767 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1156)
    2005-07-18 19:13:54,772 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.DateFormat.parse(DateFormat.java:333)
    It seems like some people have reported BugID 4228335 and there are few associated bugs. I assumed these are fixed in jdk1.4.
    Can anyone please suggest if this kind of issues still exist in jdk1.4.2?
    Here is the piece of code.
    private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public Object convert(Class type, Object inValue) {
    if(inValue == null)
    return null;
    NFDate ret = (NFDate) ClassDirectoryFactory.GetInstance().getClassInstance(NFDate.CLASS_KEY);
    if (inValue instanceof Date) {
    ret.setDate((Date)inValue);
    } else if (inValue instanceof String) {
    String str = inValue.toString();
    if (str != null && str.length() > 0) {
    DateFormat format = DateFormat.getDateTimeInstance();
    format.setLenient(true);
    try {
    ret.setDate(format.parse(str));
    } catch (ParseException e) {
    try {
    ret.setDate(DATE_FORMAT.parse(str));
    } catch (ParseException e1) {
    throw new DateConversionException("Unable to convert the String to NFDate. " +
    "Exception: " + e + " - expected format is (" + format.format(new Date()) + ")", e1);
    else {
    if (!ret.getIsNullDate()) ret.reset();
    } else {
    String msg = "Conversion from " + inValue.getClass().getName() + " to " + NFDate.class.getName() +
    " is not supported";
    throw new DateConversionException(msg);
    return ret;
    Thanks much in advance.
    Saikat

    It doesn't look like the format classes will ever be made thread safe. The fact that they aren't isn't a bug, it is a design choice that Sun made. If you need them to be thread safe, then you will have to do the synchronization yourself.
    If you have a finite number of threads for you application (like a thread pool) then you might consider using ThreadLocal so that separate threads will not be trying to access the same formatter.

Maybe you are looking for

  • Address Book and iCal Server backups

    I'm working to implement a company-wide Address Book, iCal, and iChat server via Lion Server where I work, and I've gotten most of the setup figured out (I think), and am approaching the point where I can roll it out to a few users for further testin

  • ???Transferring songs from a PC to a new Mac???

    I just bought a new iBook G4 and I desperatley need to transfer my music from my iPod to my new Mac/iTunes. I no longer have my old computer, but my entire library is still on my iPod. I would appreciate if someone could help me out with this matter!

  • Contacts entered on iPhone 4S does not sync to iCloud

    Using iCloud with an iPhone 4S (version 5.0.1). When I enter a contact on the iPhone, it will NOT sync to iCloud.  However, when I enter a contact on www.icloud.com, it WILL sync to the iPhone.  And yes, I am entering the contacts in the correct grou

  • Does ucf.jar handle symbolic links?

    When bulding a .zxp package using ucf.jar on the command line, I wish to package symbolic links which point at files which are not necessarily here on my system - they point at elements which will be installed as part of the extension. When ucf.jar e

  • HT204053 Change iCloud a/c without knowing the password

    I have purchased a second hand iPhone. But prior iPhone user hasn't clear his iCloud account on the iPhone I purchased from him  I am unable to now set my iCloud a/c :-( I don't feel safe to config my emails , contacts, etc on this phone. How do I un