Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Date Object.

Thread view: 
Mike - 06 Nov 2006 01:39 GMT
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?
Hal Rosser - 06 Nov 2006 01:57 GMT
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.

> 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?
Daniel Pitts - 06 Nov 2006 02:46 GMT
> > 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?
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
Mike - 06 Nov 2006 13:05 GMT
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.

> > > I'm trying to instantiate a Date object with year, month, day, hour,
> > > and minute.  Any ideas?  The date constructor is deprecated and
[quoted text clipped - 19 lines]
> Good luck.
> - Daniel


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.