Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert date in to yyyy-MM-dd Format?

Sat Dec 01 00:00:00 GMT 2012

I have to convert above date into below format

2012-12-01

How can i?

i have tried with following method but its not working

public Date ConvertDate(Date date){      DateFormat df = new SimpleDateFormat("yyyy-MM-dd");     String s = df.format(date);     String result = s;     try {         date=df.parse(result);     } catch (ParseException e) {         // TODO Auto-generated catch block         e.printStackTrace();     }     return date;   } 
like image 658
User 1531343 Avatar asked Dec 26 '12 10:12

User 1531343


People also ask

How do you enter a date in YYYY-MM-DD format in Excel?

First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.


1 Answers

Use this.

java.util.Date date = new Date("Sat Dec 01 00:00:00 GMT 2012"); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String format = formatter.format(date); System.out.println(format); 

you will get the output as

2012-12-01 
like image 187
Nidhish Krishnan Avatar answered Sep 19 '22 17:09

Nidhish Krishnan