import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; //员工信息类 //date类 public class test50 { private String name; private String sex; private Date birth; public void showme(){ System.out.println(this.getName()); System.out.println(this.getSex()); // System.out.println(DateFormat.getDateInstance().format(this.getBirth())); //System.out.println(this.getBirth()); SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); String data=sdf.format(birth); System.out.println(data); } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setSex(String sex) { this.sex = sex; } public String getSex() { return sex; } public void setBirth(Date birth) { this.birth = birth; } public Date getBirth(Date birth) { return this.birth; } } 测试类package com.zx; import java.util.Calendar; import java.util.Scanner; import java.util.Date; public class test54 { public static void main(String[] args){ Scanner in=new Scanner(System.in); test50 emp=new test50(); test50 emp1=new test50(); System.out.println("请输入第一个员工的姓名"); emp.setName(in.next()); System.out.println("请输入第一个员工的出生年份"); int year=in.nextInt(); System.out.println("请输入第一个员工的出生月份"); int month=in.nextInt(); System.out.println("请输入第一个员工的出生日期"); int date=in.nextInt(); Calendar cal=Calendar.getInstance(); cal.set(Calendar.YEAR,year); cal.set(Calendar.MONTH,month-1); cal.set(Calendar.DATE,date); Date birth=cal.getTime(); emp.setBirth(birth); emp.showme(); System.out.println("请输入第二个员工的姓名"); emp1.setName(in.next()); System.out.println("请输入第二个员工的出生年份"); int year1=in.nextInt(); System.out.println("请输入第二个员工的出生月份"); int month1=in.nextInt(); System.out.println("请输入第二个员工的出生日期"); int date1=in.nextInt(); Calendar cal1=Calendar.getInstance(); cal1.set(Calendar.YEAR,year1); cal1.set(Calendar.MONTH,month1-1); cal1.set(Calendar.DATE,date1); Date birth1=cal1.getTime(); emp1.setBirth(birth1); emp1.showme(); System.out.println(cal.before(cal1)); } }