aktuelles Datum ermitteln

Status
Nicht offen für weitere Antworten.

Felix

Bekanntes Mitglied
Hallo, ich möchte das aktuelle Datum ermitteln. Dazu habe ich folgendes Versucht:

Code:
Date d = new Date(System.currentTimeMillis());
		System.out.println(d.getDay() + "." + d.getMonth() + "." + (d.getYear() + 1900));

herauskam ( am 05.03.06 ) folgendes:


Scheint irgendwie falsch zu sein :lol:

Wie soll ich es sonst machen???

Gruß
der Felix
 
Ich hab jetzt:

Code:
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
		Calendar c = df.getCalendar();
		c.setTimeInMillis(System.currentTimeMillis());
		return c.DAY_OF_MONTH + "." + (c.MONTH + 1) + "." + c.YEAR;

stimmt auch alles, bis auf das Jahr.. Da kommt 1 raus... warum?
 
oh mann. du hast dir nen äußerst ungüngstiges datum ausgesucht. morgen funktinoiert das nämlich nicht mehr :roll:

aber nochmal doku lesen!!
API hat gesagt.:
Field number for get and set indicating the day of the month.
:arrow: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html#get(int)
 
OK, ich habs 🙂

und zwar geht es so:

Code:
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
		Calendar c = df.getCalendar();
		c.setTimeInMillis(System.currentTimeMillis());
		return c.get(Calendar.DAY_OF_MONTH) + "." + (c.get(Calendar.MONTH) + 1) + "." + c.get(Calendar.YEAR);

hehe

Gruß
der Felix
 
danke felix kann ich gebrauchen!

hm... obwohl ich die DateFormat Klasse importiert habe kommt beim aufruf im Konstruktors des fenster die Meldung:

symbol : class DateFormat
location: class ReleazerWindow
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
^
ReleazerWindow.java:69: cannot find symbol
symbol : class Calendar
location: class ReleazerWindow
Calendar c = df.getCalendar();
^
ReleazerWindow.java:68: cannot find symbol
symbol : class SimpleDateFormat
location: class ReleazerWindow
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
^
ReleazerWindow.java:314: cannot return a value from method whose result type is void
return c.get(Calendar.DAY_OF_MONTH) + "." + (c.get(Calendar.MONTH) + 1) + "." + c.get(Calendar.YEAR);
^
4 errors
 
Du musst noch die Klassen SimpleDateFormat und Calendar importieren. Zu der letzen Fehlermeldung: wenn du eine void Methode hast kannst du keinen Wert zurückgeben. Deine Methode müsste z. B. ein String sein.
 
Einfacher gehts nicht:

Code:
import java.util.*;
import java.text.*;

public String getDateAsString() {
   DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
   return formatter.format(new Date());
}
 
yo danke jungs habe gestern das forum durchstöbert und bin auf einen alten thread von L-ecgtron-X gestoßen, der wie seine jetztige lösung aussieht, danke dennoch!!!!
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben