0

I'm trying to get the day of the week such as "friday" from a string "2015-02-24" in java but is it possible?

There is a code to convert string, however, I want to get the day string from "2015-02-24". Since, I'm a noob I would be glad to have some tips.

SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
String dateInString = "7-Jun-2013";

try {

    Date date = formatter.parse(dateInString);
    System.out.println(date);
    System.out.println(formatter.format(date));

} catch (ParseException e) {
    e.printStackTrace();
}
Jennifer
  • 1,822
  • 2
  • 20
  • 45

2 Answers2

3

You can use the below-

String input_date="2012-08-01";
SimpleDateFormat format1=new SimpleDateFormat("yyyy-MM-dd");
Date dt1=format1.parse(input_date);
DateFormat format2=new SimpleDateFormat("EEEE"); 
String finalDay=format2.format(dt1);

Reference : Get day from date

Community
  • 1
  • 1
WISHY
  • 11,067
  • 25
  • 105
  • 197
1

Try new SimpleDateFormat("EEEE").format(new Date()); The "EEEE" should make it display the day of the week.

Gerralt
  • 221
  • 2
  • 6