Created
May 22, 2013 09:06
-
-
Save hanksudo/5626249 to your computer and use it in GitHub Desktop.
[Java] Calculate your age in days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + " 天"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, Worked :)