# datumsvergleich



## Freak2k (19. Mai 2005)

Hallo,

ich habe ein Datum in der form "19.05.2005" vorliegen!
wie ermittle ich, ob das Datum vor dem heutigen liegt?

danke!


----------



## Romsl (19. Mai 2005)

Das sollte dir weiterhelfen.


```
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;

/**
 * <p/>
 * User: rr
 * Date: 19.05.2005
 * Time: 09:06:50
 *
 * @author Romsl
 * @version $Id$
 */
public class Test {
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");

        Date date = null;
        try {
            date = sdf.parse("19.05.2005");
        }
        catch (ParseException e) {
            e.printStackTrace();
        }

        Date today = new Date();

        if (date != null)
            System.out.println("Test: " + date.compareTo(today));
    }
}
```


----------



## Thomas Darimont (19. Mai 2005)

Hallo!

Schau mal hier:

```
/*
 * Created on 19.05.2005@10:04:50 by Darimont
 *
 * TODO Licence info
 */
package de.tutorials;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Darimont
 * 
 * TODO Explain me
 */
public class DateComparisionExample {

	public static void main(String[] args) throws Exception {

		Date today = new Date(System.currentTimeMillis());

		String date = "18.05.2005";
		SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");

		Date d = sdf.parse(date);

		System.out.println("Is " + date + " before today? " + d.before(today));
		System.out.println("Is " + date + " after today? " + d.after(today));

	}
}
```

Gruß Tom


----------

