Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2006

Tip: Looking for answers? Try searching our database.

Date.getTime()

Thread view: 
fritz-bayer@web.de - 13 Jan 2006 13:39 GMT
Hi,

I'm reading in Timestamps from a Database, which originate from user
input. The dates look like this:

2006-01-12 14:00:56.0
2006-03-17 11:05:59.0
2006-02-19 21:00:00.0
...

and I read them into a Date() object using the following code:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-dd-MM
HH:mm:ss'.0'");
Date date = simpleDateFormat.parse("2006-02-19 21:00:00.0");
long milis = date.getTime();

just taking the date from a variable, of course.

Now I have noticed, that the miliseconds returned by getDate() are not
uniformly distributed when it comes to the last digit of the long
number "milis".

Most of the time it remains zero. I guess that's because the
miliisecond count is always zero in the dates, which I read in.
However, I thought that the last digit should be uniformly distributed
from 0 to 9.

That's in fact what I would like to try to achieve. Can somebody tell
me, which piece of code will turn the miliseconds returned from the
Date.getTime() function into a number, whose last digit is randomly
distributed between 0 and 9 ?

Fritz
Gordon Beaton - 13 Jan 2006 13:52 GMT
> Now I have noticed, that the miliseconds returned by getDate() are
> not uniformly distributed when it comes to the last digit of the
[quoted text clipped - 9 lines]
> the Date.getTime() function into a number, whose last digit is
> randomly distributed between 0 and 9 ?

Unless I've completely misunderstood the problem, it seems to me that
for any Date representing a time on a whole second boundary, the
number of milliseconds returned by getTime() will always be a multiple
of 1000.

Do you intend to *modify* the dates in order to achieve a random
distribution in the last digit?

Perhaps the problem is the way the timestamps are generated in the
first place, with second accuracy.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Thomas Weidenfeller - 13 Jan 2006 14:22 GMT
> Now I have noticed, that the miliseconds returned by getDate() are not
> uniformly distributed when it comes to the last digit of the long
> number "milis".

Who said they should?

> Most of the time it remains zero.

Most? Unless Sun's parsing is broken they should be zero.

> I thought that the last digit should be uniformly distributed
> from 0 to 9.

Who said this?

> That's in fact what I would like to try to achieve. Can somebody tell
> me, which piece of code will turn the miliseconds returned from the
> Date.getTime() function into a number, whose last digit is randomly
> distributed between 0 and 9 ?

A random number generator.

I have no idea what this should be good for but a random number
generator should do. Generates values from 0 to 9. Then replace the last
digit with the result from the generator (integer divide and multiply by
10, and add the new digit).

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Matt Humphrey - 13 Jan 2006 15:38 GMT
> Hi,
>
[quoted text clipped - 12 lines]
> Date date = simpleDateFormat.parse("2006-02-19 21:00:00.0");
> long milis = date.getTime();

My comment doesn't address your question, but your incoming data appears to
be yyyy-MM-dd but your format is yyyy-dd-MM.

Cheers,
Matt Humphrey  matth@ivizNOSPAM.com  http://www.iviz.com/
fritz-bayer@web.de - 15 Jan 2006 08:39 GMT
> > Hi,
> >
[quoted text clipped - 15 lines]
> My comment doesn't address your question, but your incoming data appears to
> be yyyy-MM-dd but your format is yyyy-dd-MM.

Ups that's right. I did not see this. I will change it and tell you if
it changed anything.

> Cheers,
> Matt Humphrey  matth@ivizNOSPAM.com  http://www.iviz.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.