This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes How can I get sysdate in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How can I get sysdate in java?" Watch "How can I get sysdate in java?" New topic
Author

How can I get sysdate in java?

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
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


Thanks,
Elahe
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Date d = new Date();


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
and also the return type should be date not string...
Thanks,
Elahe
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
Date sysDate = new Date();
String dateString = sysDate.toString();


Wait a minute, I'm trying to think of something clever to say...<p>Joel
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
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

Joined: Dec 12, 2001
Posts: 291
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

Joined: Jun 25, 2001
Posts: 110
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

Joined: May 05, 2000
Posts: 13974
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

Joined: Dec 12, 2001
Posts: 291
Oh I see... by the way what is the difference between java.util and java.sql ?
Thanks,
Elahe
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
java.sql is the package that contains JDBC support classes.
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How can I get sysdate in java?