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 / March 2006

Tip: Looking for answers? Try searching our database.

Deprecated Date class

Thread view: 
stixwix - 24 Mar 2006 14:46 GMT
Hi,

Is there a way to do the following without using the deprecated Date
constructor Date(String)?

Calendar calendar = new GregorianCalendar();
Date d  = new Date("Friday, 24 March 2006");
calendar.setTime(d);

thanks
Andy
Robert Klemme - 24 Mar 2006 15:09 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> Date d  = new Date("Friday, 24 March 2006");
> calendar.setTime(d);

http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html#parse(java.lan
g.String
)

    robert
Nils Bandener - 24 Mar 2006 15:11 GMT
Hi!

> Is there a way to do the following without using the deprecated Date
> constructor Date(String)?
>
> Calendar calendar = new GregorianCalendar();
> Date d  = new Date("Friday, 24 March 2006");
> calendar.setTime(d);

Yep, using java.text.SimpleDateFormat:

Calendar calendar = new GregorianCalendar();
SimpleDateFormat format = new SimpleDateFormat("E, d M y");
Date d = format.parse("Friday, 24 March 2006");
calendar.setTime(d);

(You'll have to handle some exceptions, see the API doc for these)

Bye

Nils
Roedy Green - 24 Mar 2006 19:50 GMT
>Is there a way to do the following without using the deprecated Date
>constructor Date(String)?

see http://mindprod.com/jgloss/calendar.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

John O'Conner - 24 Mar 2006 22:02 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> Date d  = new Date("Friday, 24 March 2006");
> calendar.setTime(d);

Calendar calendar = Calendar.getInstance();
calendar.set(2006, Calendar.MARCH, 24);
Date d = calendar.getTime();

How's that?

Regards,
John O'Conner


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.