0

I'm hopeless trying to parse a String to a Date but its not working. Could not be that hard? I'm doing it like this description: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

String timestamp = "05 MAY 2017 15:20:26 UTC";   
SimpleDateFormat sdf = new SimpleDateFormat("dd MMMMM yyyy HH:mm:ss z");
Date date = sdf.parse(timestamp);

But I'm still getting an error:

Exception in thread "main" java.text.ParseException: Unparseable date: "05 MAY 2017 15:20:26 UTC"
    at java.text.DateFormat.parse(DateFormat.java:366)
    at GetTime.main(GetTime.java:18)

What am I missing?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Ero Stefano
  • 556
  • 2
  • 9
  • 27

1 Answers1

2

You have to use Locale in your SimpleDateFormat for example :

SimpleDateFormat sdf = new SimpleDateFormat("dd MMMMM yyyy HH:mm:ss z", Locale.UK);
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140