Date Object.

M

Mike

I'm trying to instantiate a Date object with year, month, day, hour,
and minute. Any ideas? The date constructor is deprecated and
GregorianCalendar is the object I'm trying to use. Do you think
casting will work?
 
H

Hal Rosser

Look at SimpleDateFormat class. To create a SimpleDasteFormat object that
can parse a string like "12/25/2006" into a date. Then you can create your
GregorianCalendar object from the date object.
 
D

Daniel Pitts

Casting will not work, GregorianCalendar is not derived from Date. Read
below...
Look at SimpleDateFormat class. To create a SimpleDasteFormat object that
can parse a string like "12/25/2006" into a date. Then you can create your
GregorianCalendar object from the date object.

You ignore Hal Rosser's bad advice, and do the correct thing by using:

GregorianCalendar calendar = new GragorianCalendar(year, month, day,
hour, minute);
Date date = .calendar.getTime();

If you look in the API javadoc, you might have been able to figure that
out yourself. I suggest you try that next time for a quicker response.
:)

Good luck.
- Daniel
 
M

Mike

Thanks Daniel,

I was a bit confused honestly from looking at the javadoc. I assumed
that .getTime() would get the system's time. My assumptions were the
least bit educated. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top