• Post Reply Bookmark Topic Watch Topic
  • New Topic

getTime() method  RSS feed

 
Anders hofel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Java MySQL Database Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly are you dividing? You can't divide a Date object.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the Javadoc as I suggested ?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just in case you don't know where it is, you can find the documents here
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!