2016-04-07 19 views
1

Ich möchte umwandeln: Wed Apr 06 09:37:00 GMT + 03: 00 2016 bis 02/02/2012. Was ichAndroid Datum zu String Umwandlung Problem

SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy"); 
    Date date = sdf.parse(mydate); 

versucht und

String mydate = "Wed Apr 06 09:37:00 GMT+03:00 2016"; 
      SimpleDateFormat src = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy"); 
      SimpleDateFormat dest = new SimpleDateFormat("dd/MM/yyyy"); 
      Date date = null; 
      try { 
       date = src.parse(mydate); 
      } catch (ParseException e) { 
       Log.d("deneme",e.getMessage()); 
      } 
      String result = dest.format(date); 

aber sein give Fehler unparseable Datum: "Mi 6. April 09.37.00 GMT + 03: 00 2016" (bei Offset 0) eine Idee, wie Ich kann es analysieren?

+0

http://stackoverflow.com/questions/8911099/java-text-parseexception-unparseable-date-thu-jan-19-2012-0800-pm –

+0

@keikoman nimm meinen Code und setze ihn direkt, es wird dir das Ergebnis geben –

+0

@Kelkoman du wandelst dein Datum in Millisekunden und parst sie dann zu deinem gewünschten Format –

Antwort

0

Ich denke, Sie versuchen, ein Englisch Locale Datum zu formatieren, aber Ihr Systemgebietsschema ist nicht Englisch. Wenn Sie also das SimpleDateFormat Objekt erstellen, geben Sie die Locale Explicit an.

diesen Code Versuchen Sie,

String mydate = "Wed Apr 06 09:37:00 GMT+03:00 2016"; 
    SimpleDateFormat src = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy", Locale.ENGLISH); 
    SimpleDateFormat dest = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH); 
    Date date = null; 
    try { 
     date = src.parse(mydate); 
    } catch (ParseException e) { 
     Log.d("Exception",e.getMessage()); 
    } 
    String result = dest.format(date); 
    Log.d("result", result); 
+0

LoL tyvm akhi, es hat funktioniert. Locale.English ... –