Java Datum eingeben in die Console?
Ich möchte gern ein Script entwickeln bei der ich in der Java Konsole ein Datum eingeben kann um dann eine Frist zu berechnen. Tipps?
1 Antwort
Von gutefrage auf Grund seines Wissens auf einem Fachgebiet ausgezeichneter Nutzer
Computer
Mit einem Scanner ein Datum einlesen und dieses Formattieren:
Scanner s = new Scanner(System.in);
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.mm.yyyy", Locale.GERMAN);
try {
System.out.println("Datum:");
c.setTime(sdf.parse(s.next()));
System.out.println(sdf.format(c.getTime()));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LG
Woher ich das weiß:Studium / Ausbildung – Gelernter Fachinformatiker, Freiberufl. Softwareentwickler
Leider werden noch zwei Fehler angezeigt:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
SimpleDateFormat cannot be resolved to a type
SimpleDateFormat cannot be resolved to a type
Locale cannot be resolved to a variable
ParseException cannot be resolved to a type