Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I code a little Console program and now I store the date they joined in a database like.

CreateDate
2011-04-15 17:52:57

Now I want to do a check like this: a function that gets how many days the guy have been registered.

if(player.getDaysSinceRegistration) { 

Thanks for any help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
163 views
Welcome To Ask or Share your Answers For Others

1 Answer

joda-time has an easy way to do this:

Days.daysBetween(new DateTime(registeredDate), new DateTime()).getDays();

Without 3rd party libraries:

(System.currentTimeMillis() - registeredDate.getTime()) / MILLIS_PER_DAY;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...