0

i want to convert String "yyyy-MM-dd'T'HH:mm" (for ex,2015-04-13T10:00:00) into date object with the same format(yyyy-MM-dd'T'HH:mm). Please let me know how to do this.

Rustam
  • 6,485
  • 1
  • 25
  • 25
santro
  • 373
  • 1
  • 6
  • 22
  • 2
    Date objects don't *have* a format. You can parse using a particular format, but then when you want to convert the `Date` back into a `String`, you need to format with the same format. – Jon Skeet Sep 03 '15 at 12:07

1 Answers1

1
String dateString = "2015-04-13T10:00:00";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); 
Date date = simpleDateFormat.parse(dateString);

Now if you want to display the date in the same format, you can do the following

System.out.println(simpleDateFormat.format(date)); // Outputs "2015-04-13T10:00"
Kevin
  • 2,813
  • 3
  • 20
  • 30