2016-04-07 24 views
1

Dönüştürmek istiyorum: Çarşamba 07 09:37:00 GMT + 03: 00 2016 - 02/02/2012. iAndroid date to dize dönüşüm sorunu

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

ve

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); 

ancak vermek hatası Ayrıştırılamayan tarih çalıştı Ne : "Pts Nis 06 09:37:00 GMT + 03: 00 2016" (ofset 0) herhangi bir fikir nasıl onu ayrıştırabilir miyim?

+0

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

+0

@keikoman benim kod almak ve doğrudan koymak o size sonuç verecektir –

+0

@Kelkoman tarihinizi miliseconds dönüştürmek ve daha sonra istediğiniz formatta onları ayrıştırmak –

cevap

0

İngilizce yerel ayar tarihini biçimlendirmeye çalıştığınızı düşünüyorum, ancak sistem yerel ayarınız ingilizce değildir. Bu nedenle, SimpleDateFormat nesnesini oluşturduğunuzda, Locale açıklamasını belirtin.

bu kodu deneyin,

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, onun çalıştı. Locale.English ... –