Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Created May 22, 2013 09:06
Show Gist options
  • Save hanksudo/5626249 to your computer and use it in GitHub Desktop.
Save hanksudo/5626249 to your computer and use it in GitHub Desktop.
[Java] Calculate your age in days
import java.util.Calendar;
import java.util.Date;
public class LiveDays {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
Date today = cal.getTime();
cal.set(1985, Calendar.JANUARY, 30);
Date birthday = cal.getTime();
long dateSubtract = today.getTime() - birthday.getTime();
long time = 1000 * 60 * 60 * 24;
System.out.println("我已經活了 " + dateSubtract / time + " 天");
}
}
@KhanStan99
Copy link

Thanks, Worked :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment