datumsvergleich...

Status
Nicht offen für weitere Antworten.

MASTERII

Mitglied
hi,
ich hab folgendes problem...
ich habe ein Formular das dem Nutzer die moeglichkeit bietet in 2 feldern daten einzutragen(gültig ab : und gültig bis :), auf knopfdruck soll nun geprueft werden ob die eingaben sich ueberschneiden also ob logische felhler enthalten sind.
beispielsweise bei eingabe :

gültig ab : 12.10.1970 gültig bis : 12.9.1970

soll eine wahrnung kommen die den user zur korrektur auffordert.....

alles ausenrumm(exception , wahrnung usw.) hab ich schon , nun fehle mir nur noch die wandlung der eingabe in ein date und der nachfolgende Vergleich der 2 daten.....
mfg
 

mariopetr

Bekanntes Mitglied
SimpleDateFormat:
parse
public Date parse(String text,ParsePosition pos)
Parses text from a string to produce a Date.
The method attempts to parse text starting at the index given by pos. If parsing succeeds, then the index of pos is updated to the index after the last character used (parsing does not necessarily use all characters up to the end of the string), and the parsed date is returned. The updated pos can be used to indicate the starting point for the next call to this method. If an error occurs, then the index of pos is not changed, the error index of pos is set to the index of the character where the error occurred, and null is returned.
Specified by:
parse in class DateFormat
Parameters:
text - A String, part of which should be parsed.
pos - A ParsePosition object with index and error index information as described above.
Returns:
A Date parsed from the string. In case of error, returns null.
Throws:
NullPointerException - if text or pos is null.
See Also:
DateFormat.setLenient(boolean)

Date:
int compareTo(Date anotherDate)
Compares two Dates for ordering.
 

Ebenius

Top Contributor
Das javax.swing.JFormattedTextField macht die Sache ein bisschen einfacher. Einfach mal bei sun durchlesen, wie das funktioniert. Richtig initialisiert gibt es Dir ein Date-Object zurück. Die beiden (da zwei Eingabe-Felder) Date's kannst Du dann einfach überprüfen mit:

Code:
date1.getTime() - date2.getTime()

Gruß, Ebenius
 

MASTERII

Mitglied
aber ich muss sagen die methode mit vorformatiertem textfeld gefäält mir besser...
danke fuer die hilfe !!!!!!
 
Status
Nicht offen für weitere Antworten.

Oben