• Post Reply Bookmark Topic Watch Topic
  • New Topic

I cannot insert a value into my date variable.  RSS feed

 
Kenrick Gaw
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Java Professionals,
I cannot insert a value into my Date variable, please guide me, thanks in advance.

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The "010320" in your code is an octal integer literal. Why would you think that it is assignable as a Date object?

Henry
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
… and welcome to the Ranch
 
Kenrick Gaw
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What should I insert or what should I do to solve this?
 
Kenrick Gaw
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
is my following code correct?

 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kenrick,
If you don't know what to pass to a constructor or a method, the first thing to do is check out the Java API. Here is the documentation for the Date class.
 
Kenrick Gaw
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Charles,
thanks.I know how to pass methods and value into a constructor and I only don't know how to pass the value into a date object. Finally, I have discovered this Contract c1 = new Contract(new Date(115,3,13),3.0); is the method after discussing.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain what the three numbers in the Date constructor call mean.
 
Kenrick Gaw
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2015-1900=115 This is the formula to calculate the current year.
3 = April because the month is from 0-11 and 0 represents January.
13 is the day.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can start using the Java 8 Date/Time API, you should. See this tutorial: https://docs.oracle.com/javase/tutorial/datetime/

If you keep using the old Date/Calendar classes in new code, you only help perpetuate the problems that their poor designs cause.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!