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 ?
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 ?
Use java.text.SimpleDateFormat.
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy");
String formattedDate = dateFormatter.format(dateInstance);
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.
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());