GeeCON Prague 2014*
The moose likes Java in General and the fly likes HELP - java.sql.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "HELP - java.sql.Date" Watch "HELP - java.sql.Date" New topic
Author

HELP - java.sql.Date

Jason Barker
Greenhorn

Joined: Nov 03, 2003
Posts: 17
This is my first post so if I am doing this incorrectly, please don't flame me! Thanks.
If I have a month, day and year and I want to create a Date object, what is the best way to go about this? Is there a way to get a Date object based on the current date? If I have a GregorianCalendar object, is there a way to convert from it to java.sql.Date?

Thanks in advance!
Jason
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8913
    
    8


If I have a month, day and year and I want to create a Date object, what is the best way to go about this?

Where year, month and day are integers:
new java.sql.Date(year, month, day);

Is there a way to get a Date object based on the current date?

java.sql.Date doesn't have a no-argument constructor to get the current time, but java.util.Date does:
new java.sql.Date(new java.util.Date().getTime());

If I have a GregorianCalendar object, is there a way to convert from it to java.sql.Date?

new java.sql.Date(gregorianCalendar.getTimeInMillis());


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jason Barker
Greenhorn

Joined: Nov 03, 2003
Posts: 17
Thank you! That does the trick!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP - java.sql.Date