• Post Reply Bookmark Topic Watch Topic
  • New Topic

replacement for date.getMonth()  RSS feed

 
Karina Guenther
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Karina Guenther
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answers. BTW I'm embarrased about the today(). I probably mixed up my languages.

:roll:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!