出生到现在多少天

来源:互联网 发布:微商软件必备 编辑:程序博客网 时间:2024/04/27 21:47
import java.util.Calendar;


/**
 * @author Rory
 * @category 计算出生到现在共多少天
 */
public class Birthday {
private int year;
private int month;
private int day;


public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}

public long getHours(){
Calendar c= Calendar.getInstance();//获取日历
c.set(year,month,day);   //设置出生日期
return(System.currentTimeMillis()-c.getTimeInMillis())/(1000L*60*60*24);

}

public static void main(String[] args) {
Birthday b=new Birthday();
//出生日期
b.year=1994;
b.month=10;
b.day=28;
System.out.println("今天是第"+b.getHours()+"天");

}

}
0 0
原创粉丝点击