-2

I have a Date Object (Fri Dec 31 00:00:00 CET 1999) and i just want to display 31-12-1999.

And i don't want use String Object for display this information i need to display with a Date Object.

Do you got a solution for this problem ?

3
  • 1
    display <=> string (or at least some sort of charsequence) Commented Aug 29, 2012 at 15:04
  • Neither String nor Date actually display anything. They're containers for different kinds of data. System.out.prinln and the like display things, and System.out.println displays a String. Commented Aug 29, 2012 at 15:05
  • 1
    You're not going to find any way to display anything without a String somewhere. Commented Aug 29, 2012 at 17:04

3 Answers 3

4

Use java.text.SimpleDateFormat.

SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy");
String formattedDate = dateFormatter.format(dateInstance);
Sign up to request clarification or add additional context in comments.

Comments

1

You can write the Date as text directly to a ByteBuffer which you can write to an IO device. This can be used to speed up logging for example.

The logic for converting dates with timezones is so complex however, I would suggest you use the standard libraries or JodaTime for dates as its not worth trying to write yourself.

For this reason, I write times directly to a ByteBuffer and use SimpleDateFormat to produce a cached String for the date (as it only changes once per day)

If you want to display to a GUI, you will have to use a String because that what the GUI uses.

Comments

1

Do you mean you need to remove the time information from the Date object? You can do something like this.

Date d; // this is your date 
Date dateWithoutTime = new Date(d.getYear(), d.getMonth(), d.getDay());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.