1

I have the following String that represents a Date:

2017-01-30T19:00:00+0000

I would like to change it to a Date Object using SimpleDateFormat.

What is the correct format for this string?

I have read the SimpleDateFormat API and cant see anything relating to a T?

java123999
  • 6,974
  • 36
  • 77
  • 121
  • Put it in single quotes: `....'T'....`. It's just a literal `T` in the string. – Andy Turner May 19 '17 at 09:11
  • 1
    But really, don't use `Date` and `SimpleDateFormat`. Use the classes in `java.time` which are not awful and full of deprecated, broken methods. – Andy Turner May 19 '17 at 09:12
  • I am still unable how to convert this to a date object? Can you please show with an Answer? – java123999 May 19 '17 at 09:13
  • You have a date string in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. See this question: [Converting ISO 8601-compliant String to java.util.Date](http://stackoverflow.com/questions/2201925/converting-iso-8601-compliant-string-to-java-util-date) – Jesper May 19 '17 at 09:16

1 Answers1

0

Try to use :

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String dateString = "2017-01-30T19:00:00+0000";
try {

    Date date = formatter.parse(dateString);
    System.out.println(date);

} catch (ParseException e) {
    //throw exception
}
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140