Java Datum eingeben in die Console?

1 Antwort

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
saschaMi 
Fragesteller
 17.06.2020, 12:54

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

0
saschaMi 
Fragesteller
 17.06.2020, 13:07
@saschaMi

Habs geschafft! Nun kann ich mich der Fristenberechnung zuwenden :) DANKE!!!!!

0