Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I get sysdate in java?

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
Could you tell me how can I get sysdate in my java program to put it in my table?(I know I have to use today() I guess!!! but how?
Thanks,
Elahe
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Date d = new Date();
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and also the return type should be date not string...
Thanks,
Elahe
 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Date sysDate = new Date();
String dateString = sysDate.toString();
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe,
I used that but it gives me this error and even though setSubmittedDate is date type in oBug.
Do you have any idea?
Thanks,
ELahe
No method found matching setSubmittedDate(Date)
oBug.setSubmittedDate( dtSubmittedDate );
^
1 error

and here is part of Bug
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed the problem by adding java.sql.Date as you can see bellow:
java.sql.Date dtSubmittedDate = new java.sql.Date(new Date().getTime());
but why it should get fix by adding this I want to know the reason not just solved it!!!
Any idea?
Thanks,
Elahe
 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
U'll have to see the type of Date imported in Bug class(java.util.Date or java.sql.Date)...This may lead to a conflict...If u r using it to update to database, then better use java.sql.Date, to be on the safer side.

Mahesh
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you imports for both java.util and java.sql, you could have a problem as both packages have a Date class in them.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I see... by the way what is the difference between java.util and java.sql ?
Thanks,
Elahe
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.sql is the package that contains JDBC support classes.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic