This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization 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
Posts: 15207
36
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
Posts: 15207
36
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