programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# getTime() method

Anders hofel
Greenhorn
Posts: 9
Hello.

Have two dates.

Date d1 = new Date()
Date d2 = new Date(2013,12,03) - just a random date.

i divide both outcomes by 1000/60/60/24/365, to get years roughly.

i get d1 = 43 years
d2 = 1945 years..

why is d2 not behaving as intended?

Ashish Dutt
Ranch Hand
Posts: 172
And how would you like it to behave?
If possible please do post the complete code .. for with this current code there could be endless questions and answers...

Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
What exactly are you dividing? You can't divide a Date object.

Stuart A. Burkett
Ranch Hand
Posts: 679
Anders hofel wrote:Date d2 = new Date(2013,12,03) - just a random date.

d2 = 1945 years..

why is d2 not behaving as intended?

It is behaving as intended. Read the javadoc for this version of the constructor.

Anders hofel
Greenhorn
Posts: 9
Here's the method.

Make the date into values of milliseconds since jan 1. 1970. And turn that value into years (i need it in days, but its just for clarity)

As mentioned, the getFromDate() is: new Date()
And the, getToDate() is : new Date(2013,12,03)

Hopy you understand the problem now.

Somehow there is a problem when the parameters of the new Date() is not empty.

Stuart A. Burkett
Ranch Hand
Posts: 679

Winston Gutkowski
Bartender
Posts: 10575
66
Anders hofel wrote:As mentioned, the getFromDate() is: new Date()
And the, getToDate() is : new Date(2013,12,03)
Hopy you understand the problem now.

We understand the problem; it's you that doesn't understand the advice.

1. The constructor you're using is deprecated; which basically means: don't use it.
2. You plainly haven't read the API docs for it; otherwise you'd understand the advice you've been given.

Read the docs. If you still have questions after you've done so, feel free to come back.

Winston

fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Just in case you don't know where it is, you can find the documents here