So I have a Date object and I want to create a method so that it prints the Date in the following format:
11 September 2011, 9:15pm
How do I do that?
As of now I am just doing a toString to the date and it gives me all the GMT information and seconds precision that I don’t need. Do I have to use a DateFormatter or is there an easier way to do this?
This was edited to include Java ME in the title and the tags after some of the answers that were correct for the original question were posted.
You may use
SimpleDateFormatclass to format your date.http://download.oracle.com/javase/1,5.0/docs/api/java/text/SimpleDateFormat.html
I guess the pattern would be something like this:
EDIT for Java ME;
I read that there is no SimpleDateFormat class in Java ME specs. So I would try Calendar;
First put your date to the Calendar, then get all you need. Better is make this a method