2 Replies Latest reply: Nov 16, 2012 1:13 AM by Caddick RSS

    Unparsable Date

    Caddick
      Guys,

      I am trying to convert "130041396000000000" which is (1/31/2013) , into Date Value , but I am not able to get hold on it.

      is any one have any code to string value into Date.

      Thanks,
      Hemant.
        • 1. Re: Unparsable Date
          Nishith Nayan
          use below code and you will get this:


          final String secondsInHourStr = (60 * 60) + "";

          //Convert the huge number to hours
          BigInteger big = new BigInteger("130041396000000000");
          //Note, I got the spitByValue after trial/error testing, hope its correct
          String splitByValue = "10000000";
          BigInteger secondsBig = big.divide(new BigInteger(splitByValue));

          BigInteger hoursBig = secondsBig.divide(new BigInteger(secondsInHourStr));

          //Get the remaining seconds
          BigInteger modSeconds = secondsBig.mod(new BigInteger(secondsInHourStr));
          //Create a Calender object representing 1601-01-01 00:00:01
          Calendar cal = Calendar.getInstance();
          cal.set(Calendar.YEAR, 1601);
          cal.set(Calendar.MONTH, 0);
          cal.set(Calendar.DATE, 1);
          cal.set(Calendar.HOUR, -12);
          cal.set(Calendar.MINUTE, 0);
          cal.set(Calendar.SECOND, 1);


          //Add the hours
          cal.add(Calendar.HOUR, hoursBig.intValue());


          //Add seconds
          cal.add(Calendar.SECOND, modSeconds.intValue());

          //Here is your Java object
          Date date = cal.getTime();
          System.out.println(date);
          • 2. Re: Unparsable Date
            Caddick
            Nishith Sirji,

            Thanks a lot.

            Cheers,
            Hemant.