初学者求教

07-09-25 baimin00605

大家好,我是一个初学者,有一个问题想请教各位,谢谢!

boolean after(Date dt)

在java.util包里边有个Date类,它里的boolean after(Date dt)方法是说如果日期在指定日期之后,返回TRUE,我不知道这个方法怎么写,写了好几次不对,请大家帮忙写个简单的类,用到这个方法,我主要不知道括号里的参数怎么写,最好有注解!

xyz0102
2007-09-26 11:11

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

public static void main(String[] args) {

String f1 = "yyyy-MM-dd HH:mm:ss";

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date t = new Date();

Calendar c = Calendar.getInstance();

c.setTime(t);

c.add(Calendar.DAY_OF_YEAR, -1);

if (c.getTime().before(t)) {

System.out.println(sdf.format(c.getTime()) + " :在: "

+ sdf.format(t) + "之前");

} else {

System.out.println(sdf.format(c.getTime()) + " :在: "

+ sdf.format(t) + "之后");

}

String time = "20070901";

try {

Date t1 = sdf.parse("2007-09-08 12:43:54");

if (t1.before(t)) {

System.out.println(sdf.format(t1) + " :在: " + sdf.format(t)

+ "之前");

} else {

System.out.println(sdf.format(t1) + " :在: " + sdf.format(t)

+ "之后");

}

} catch (Exception e) {

e.printStackTrace();

// TODO: handle exception

}

}

baimin00605
2007-09-26 23:45

谢谢你,我还得研究研究也能看明白,呵呵!