aspose file tools*
The moose likes Beginning Java and the fly likes Why is my date not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why is my date not working?" Watch "Why is my date not working?" New topic
Author

Why is my date not working?

Angela Hill
Greenhorn

Joined: Jun 13, 2012
Posts: 19
I am having trouble finding out the reason why my code is broken @ ~ line 121: date1=SDF.parse(inputText,pos); cal1.setTime(date1); And again @~ Line 128: getDate2 date2= new getDate2();
If anybody could please help!!! I really do not see what I am doing wrong. I'm sure it is probably something simple that I am over looking.

Thanks in advance



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Broken? In what way? Please read our FAQ pages ItDoesntWorkIsUseless and TellTheDetails, which describe better ways of explaining your problem.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  69
Legions of men and women have been asking themselves the same question
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

SimpleDateFormat.parse() returns a java.util.Date object. In line 120 you are assigning the return value of this method to a "getDate" object. (Where's class "getDate", is that a class you wrote yourself?). That doesn't work, because "getDate" is not the same class (or a superclass) of java.util.Date.

Likewise, Calendar.setTime() needs a java.util.Date object, not a "getDate" object.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 73
Surely the code is a little messed up but...

If you want others to understand it, put the code of all your classes (getDate and getDate2) and put what do you see wrong on the program's behaivour.

But at first glance... where is inputText variable declared? I don't find it.

And... are you trying to instantate methods?
Angela Hill
Greenhorn

Joined: Jun 13, 2012
Posts: 19
Sorry for the confusion.... the errors I am getting for line 120. Is saying that I am not declaring the variable... What I am trying to get the code to do is to read the input of Today's date, I also need the cal1.SetTime(date1) to be incorporated with this as well. In other words the input is March 20, 2012. this is then set as date1 so when declared in date2 it counts the days from each transaction to then figure the interest earned. I hope this helps. Once again thanks in advance for any help.
Angela Hill
Greenhorn

Joined: Jun 13, 2012
Posts: 19
yes the getDate is what I wrote myself
Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 73
You are not assigning the result from the call of br.readLine() on line 116.

you'd probably want to do this String inputText=br.readLine();

Just look how you do it on line 42

This
input = Float.parseFloat(br.readLine());

is equivalent to this

String inputText=br.readLine();
input = Float.parseFloat(inputText);

I hope this helps you

I insist the you should post the code of getDate and getDate2 classes ,as you could have problems with that also.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

Angela Hill wrote:What I am trying to get the code to do is to read the input of Today's date...

I'm a bit confused. Why do you need to "read the input of today's date"? Today's date is today's date, and you set it with something like
new GregorianCalendar();
from which you can get a Date, a millisecond offset, or pretty much anything else you like.

Could you elaborate?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Angela Hill
Greenhorn

Joined: Jun 13, 2012
Posts: 19
Alex~ Thank you that did help a lot! I can't believe I didn't think of that!... The code below is all that I have written for getDate and getDate2. Where the notes are that the code is still broken I am getting errors...At line 9 it says incompatible types. Then at line 10 the error shows:

method setTime in class java.util.Calendar cannot be applied to given types;
required: java.util.Date
found: edu.umsl.mis3806.getDate
reason: actual argument edu.umsl.mis3806.getDate cannot be converted to java.util.Date by method invocation conversion


The error at line 17 says that the assigned value is never used and that it is not assigned. which to me does not make sense because I thought that is what I was trying to do. if that makes sense? :s
Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 73
As Calendar's method setTime needs a Date object the easiest way I'm capable to think of is create a method that returns a Date object based on a getDate Object.



James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

I think you may need to read up on Java standards regarding naming. You should never name a class getDate.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

Angela Hill wrote:Alex~ Thank you that did help a lot! I can't believe I didn't think of that!... The code below is all that I have written for getDate and getDate2.

I hate to say, but I'm still mystified. Why are you asking somebody to enter 'today's date'? If it's for a game, and it's Stardate 3274.3, I can understand; otherwise the System knows what today's date is.

As for a future date, both Date and GregorianCalendar are Comparable, so I'm not quite sure why you're going through a lot of convoluted logic to work out whether it's a future date or not. If you feel you have to, get 'today's' date, and compare it (with compareTo()) with a similarly entered 'future' date; if the the second isn't greater than the first...bingo, you have an error.

HIH

Winston
Angela Hill
Greenhorn

Joined: Jun 13, 2012
Posts: 19
Winston,
The point of know todays date is stimulating the day that the account is opened and thus the future date...well a date in the future. The point of knowing these dates are to see how much interest is earned.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

Angela Hill wrote:Then at line 10 the error shows:

method setTime in class java.util.Calendar cannot be applied to given types;
required: java.util.Date
found: edu.umsl.mis3806.getDate
reason: actual argument edu.umsl.mis3806.getDate cannot be converted to java.util.Date by method invocation conversion

The compiler is exactly saying what I explained above.

Calendar.setTime() takes a java.util.Date but you are trying to pass it a edu.umsl.mis3806.getDate.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is my date not working?