Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Gregorian Calandar

 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the above code please note the first line after the try block.
This uses the Date class of which I understand is depicted.
Does anyone know whether or not there is a similiar method in the Gregorian Calander?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15437
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"In the above code please note the first line after the try block."

Do you mean this line:

Date formattedDate = sdf.parse(inputDate);

"This uses the Date class of which I understand is depicted."

"Depicted"? Do you mean "deprecated"? No, there's nothing that's deprecated in that line. Does the compiler tell you that you're using a deprecated method? Can you please copy and paste the exact error message here?
 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean the line:

So you are looking for a parse method in a (Gregorian)Calendar?
Anyway ... the answer is sorta' because a DateFormat derived class has an associated Calendar that tells it how to interpret milliseconds (i.e. Date) into Calendar fields, which DateFormat can then turn into Strings. The (usually default) Locale gets mixed in there too so the language is correct. So the (Gregorian)Calendar is already involved in the parse.
See DateFormat.getCalendar() and DateFormat.setCalendar().

Of course, you can also do a Calendar.getTime() to go the other direction.

Hope this helps.
 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jasper Thank you for your response.

I have no error message.
My understanding is the Date class has been deprecated and replaced using the Gregorian Calandar so I'm attempting to get an understanding.

Are you implying that the SimpleDateFormat can be used for the Gregorian Calander?

Therefore I would use
Calendar c = Calendar.getInstance();
c.set(sdf);
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My understanding is the Date class has been deprecated and replaced using the Gregorian Calandar so I'm attempting to get an understanding.

Your understanding is not quite right. java.util.Date is not deprecated, however the vast bulk of its methods have been. If you look at the JavaDocs you'll see which methods.


Are you implying that the SimpleDateFormat can be used for the Gregorian Calander?

Yes you can parse a String representation of your Date with SimpleDateFormat.
 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks all - I'll do some further reading in the API
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15437
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use deprecated classes or methods, the compiler will give you a warning message.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic