Tarihi bir biçime dönüştürdüğüm bir koşul var, ayrılmayacak bir Tarih İstisnası alıyorum. Sınıf için kodJava Tarih Ayrıştırma Özel Durum
public class DateTester {
public static void main(String[] args) {
// TODO Auto-generated method stub
String stringDate = "Fri Feb 26 14:14:40 CST 2016";
Date date = convertToDate(stringDate);
System.out.println(date);
}
public static Date convertToDate(String date) {
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
Date convertedCurrentDate = null;
try {
convertedCurrentDate = sdf.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
return convertedCurrentDate;
}
}
İlk önce String'ten Date (Tarih) nesnesini/parse'sini yaratmanız ve sonra tarih nesnesini String'e veya istediğiniz herhangi bir şeye dönüştürmeniz gerekir. – kosa
StringDate biçiminiz ve ayrıştırma formatınız aynı değil. Bakınız: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html – kevingreen
'" Cuma 26 14:14:40 CST 2016 "' a benzemiyor "MM-dd-yyyy" 'nin – Bohemian