0

My Date format Example = "jan 14, 2015" Now I convert this string date to Timestamp But this Code Throws ParseException.

format = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss", Locale.ENGLISH);

     try {

          format.setTimeZone(TimeZone.getTimeZone("Asia/Bangladesh"));
          Date date = format.parse(str_date);
          Timestamp timeStampDate = new java.sql.Timestamp(date.getTime());

          return timeStampDate;
        } catch (ParseException e) {
          e.getCause().printStackTrace();
          return null;
        }

So How can I Solve this Exception??? Thanks in Advance.

Jens
  • 67,715
  • 15
  • 98
  • 113
  • 1
    Well yes, look at the string you've got vs the format you're specifying... where are the hour/minute/second values? – Jon Skeet Oct 24 '16 at 07:21
  • Can you show us the whole code? Is there a difference between `format` and `formatter` or where is the last one defined? What is `str_date`? What's the text of the printed `ParseException`? – Niklas P Oct 24 '16 at 07:23
  • refer this http://stackoverflow.com/a/30341685/1966655 – swapnil gandhi Oct 24 '16 at 07:24

1 Answers1

4

change your pattern to: format = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH); because you do not have a time part

Jens
  • 67,715
  • 15
  • 98
  • 113