Forums Register Login

replacement for date.getMonth()

+Pie Number of slices to send: Send
what do you use instead of this as it's deprecated when you have Date currentDate = today();

I'm having difficulty understanding the calendar class and how you use it. I've not found any good explanation on how to use it in relationship with formating and Date.

I understand simpleDateFormat (mostly)
+Pie Number of slices to send: Send
Hi,
As you have mentioned most methods of Date class are deprecated.The Calendar class is a abstract class,when you call the static getInstance() method on this class,you get a concrete class that extends Calendar class(usually it's java.util.GregorianCalendar).

The Calendar class has
1.Fields-these fields holds the state,these fields can be used to set the date,time
2.Methods-these can be used to incremented date,time,roll the date,represent the date,time in milli seconds

The Date class is useful to get the current timestamp.
Take a look at the Calendar API

Date currentDate = today();


By the way what is today(),just curious

Regards,
Srikkanth.M
[ June 01, 2007: Message edited by: Srikkanth Mohanasundaram ]
+Pie Number of slices to send: Send
Here is code to get the current month. Note that the month is zero-based.



Note that the date:

06/01/2007

is ambiguous since some English-speaking countries, such as Australia, use the format:

DD/MM/YYYY

and in the USA, we use the format

MM/DD/YYYY

The international format is:

June 1st 2007.

This is suitable for all English-speaking countries, but is harder to parse to turn the date-string back into a date.

Kaydell
+Pie Number of slices to send: Send
Maybe this will help:

From: "Sun Certified Programmer for Java 5 (SCJP 5) Study Guide": Exam Objective 3.4


"java.util.Date Most of this class's methods have been deprecated, but you can use this class to bridge between the Calendar and DateFormat class."



Kaydell
+Pie Number of slices to send: Send
Thanks for the answers. BTW I'm embarrased about the today(). I probably mixed up my languages.

:roll:
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 20182 times.
Similar Threads
Number of days between the 2 given dates.
getting System time
Checking Date
Set a default value for spinner
Short/Long day?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:00:19.