How to get day from specific date in Java

Code:

import java.util.*;
import java.text.*;
import java.time.LocalDate;
class Test{
    public static void main(String []argh) throws  ParseException
    {
         int month,day,year;
Scanner scan=new Scanner(System.in);

day=scan.nextInt();
month=scan.nextInt();
year=scan.nextInt();

/*
Can Do with this two line Also

LocalDate dt = LocalDate.of(year, month, day);
System.out.print(dt.getDayOfWeek());
*/

String s = new String(""+day+"/"+month+"/"+year+"");

Date date1=new SimpleDateFormat("dd/MM/yyyy").parse(s);

SimpleDateFormat simpleDateformat   = new SimpleDateFormat("EEEE");

String dayOfWeek = simpleDateformat.format(date1);

System.out.println(dayOfWeek.toUpperCase()); 
    }
}



Ouput:



Previous
Next Post »