Article View: borland.public.jbuilder.java.language
Article #17144Re: Get current date
From: Steve Waters
Date: Sun, 13 Dec 1998 00:00
Date: Sun, 13 Dec 1998 00:00
71 lines
2842 bytes
2842 bytes
Why not extend the class to do what you want? Regards Steve Michael Nguyen wrote: > Franck, > > The problem is that getTime (0 includes hour, minutes, and seconds as well. > So I wont' be able to compare just the dates but not the time. > A sample output of date from getTime is > > Thu Dec 10 18:03:43 PST 1998 > > To clear the hour, minutes, and seconds, I would need to > call setHour, setMinute, and setsecond. But these methods are > deprecated as well. I need to clear out the time, so that > when I read a date from user input, which does not have the time part, > I can compare it against the current date via > > Date.equals () and Date.after (). > > Michael, > > Franck Rasolo wrote: > > > Michael, > > > > It's actully as straightforward as this :- > > > > // Rather than creating an object GregorianCalendar which > > // won't be used afterwards, call Calendar's static method > > // Calendar.getInstance() > > > > Date date = Calendar.getInstance().getTime(); > > > > To check that you've got the right date, the easiest way is to print > > the newly created date to your console :- > > > > System.out.println(date.toString()); > > > > I hope this helps. > > > > Franck > > > > Michael Nguyen wrote: > > > > > > I use the following approach to get the current date only without the > > > curent minutes and seconds, so that I can compare the dates > > > without comparing the time. However, the Date constructor is > > > deprecated. > > > What is the alternative and non-deprecated method of getting the > > > current date without the time ? > > > > > > Date curr_date = new Date (calendar.get (Calendar.YEAR) - 1900, > > > calendar.get (Calendar.MONTH), calendar.get > > > (Calendar.DAY_OF_MONTH)); > > > > > > Thanks for the info. > > > > > > Michael, > > > > _________________________________________________________________ > > > > Franck Rasolo > > Netspin Ltd Phone: +44 (0)958 750 712 > > 7 Hill Street Fax : +44 (0)117 925 2515 > > Bristol BS1 5PU Email: franck@netspin.co.uk > > U.K. > > _________________________________________________________________
Technical Details
Message-ID:
<36735042.40596768@bellsouth.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<366F13D2.11F2FBB9@home.com> <366F5A12.DF3930B6@netspin.co.uk> <36707E8F.B86A1CD3@home.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,f08bdc690f36e25a X-Google-Attributes: gidf74b3,public From: Steve Waters <steve_w@bellsouth.net> Subject: Re: Get current date Date: 1998/12/13 Message-ID: <36735042.40596768@bellsouth.net> X-Deja-AN: 421713766 Content-Transfer-Encoding: 7bit References: <366F13D2.11F2FBB9@home.com> <366F5A12.DF3930B6@netspin.co.uk> <36707E8F.B86A1CD3@home.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language