I want the Date to be in this format
05-07-2007,
But I get
5-7-2007 and I don't want it.
how can I do that? ( 05-07-2007)
any suggestions?
Printable View
I want the Date to be in this format
05-07-2007,
But I get
5-7-2007 and I don't want it.
how can I do that? ( 05-07-2007)
any suggestions?
Use the SimpleDateFormat class.
try {
// Some examples
DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
Date date = (Date)formatter.parse("01/29/02");
formatter = new SimpleDateFormat("dd-MMM-yy");
date = (Date)formatter.parse("29-Jan-02");
// Parse a date and time; see also
// e317 Parsing the Time Using a Custom Format
formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
date = (Date)formatter.parse("2002.01.29.08.36.33");
formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
date = (Date)formatter.parse("Tue, 29 Jan 2002 22:14:02 -0500");
} catch (ParseException e) {
}