aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes printf for dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "printf for dates "Date/Time Conversions"" Watch "printf for dates "Date/Time Conversions"" New topic
Author

printf for dates "Date/Time Conversions"

Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

From here it is a little unclear how to format dates with printf.

Is anybody comfortable in using them and does not mind listing a few examples with the 3 categories they list in the above javadoc? (time, date, time/date)

PS: They are not listed in the objectives explicitly.. but as far as I understood you can never assume anything with this exams.
Thanks in advance.


OCAJP 7, OCPJP 7
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Nick,
I always use SimpleDateFormat to print dates so I've never used printf for them. Consider these two pieces of code. Which is easier to read? I think the second is by a landslide. (This is an example from the link you gave - I just made the SimpleDateFormat example.)





As far as the exam, the most common printf flags are on it. The objectives lists which flags you need to know. None of which are date/time flags.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

Thanks for responding, I have a basic understading of 't' plus anycombination, however there are many conversions character like the following:

'R' Time formatted for the 24-hour clock as "%tH:%tM"
'T' Time formatted for the 24-hour clock as "%tH:%tM:%tS".
'r' Time formatted for the 12-hour clock as "%tI:%tM:%tS %Tp". The location of the morning or afternoon marker ('%Tp') may be locale-dependent.
'D' Date formatted as "%tm/%td/%ty".
'F' ISO 8601 complete date formatted as "%tY-%tm-%td".
'c' Date and time formatted as "%ta %tb %td %tT %tZ %tY", e.g. "Sun Jul 20 16:17:00 EDT 1969".


which I have not been able to see examples of.

I really hope that they won't be in the exam.. otherwise would be a memery checking test.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Nick Widelec wrote:I really hope that they won't be in the exam.. otherwise would be a memery checking test.

When I took the exam, there weren't any questions of this sort so I'm inclined to trust them on which formatting types are covered.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: printf for dates "Date/Time Conversions"