🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #334

java.sql.Date (homework)

#334
From: Petar Popara
Date: Thu, 01 Dec 2005 17:56
18 lines
1406 bytes
I have a date of birth as:

java.sql.Date dateOfBirth = ...; // get from DB

I have java.util.Date as current time:

java.util.Date now = new java.util.Date();

I need to calculate how many years is someone old. I have tried this:

long oldnessInMillis = now.getTime() - dateOfBirth.getTime();
long oldnessInYears = (oldnessInMillis / (1000 * 60 * 60 * 24 * 365));

but I got unexpected results (bigger 21.5 times). Is it because of time 
zones or I have miscalculated it?

Thank you in advance. :> 
Technical Details
Message-ID: <438f392a@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,6ccfb3de53be2ae,start
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Petar Popara" <none>
Newsgroups: borland.public.jbuilder.java.language
Subject: java.sql.Date (homework)
Date: Thu, 1 Dec 2005 18:56:38 +0100
Lines: 20
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 193.95.248.197
Message-ID: <438f392a@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1133459754 193.95.248.197 (1 Dec 2005 09:55:54 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail