Get Day of Week in your name in Java
Description
The following code shows how to get Day of Week in your name.
Example
// w w w .j a va 2 s .c om
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar now = Calendar.getInstance();
System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-"
+ now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR));
String[] strDays = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thusday",
"Friday", "Saturday" };
// Day_OF_WEEK starts from 1 while array index starts from 0
System.out.println("Current day is : " + strDays[now.get(Calendar.DAY_OF_WEEK) - 1]);
}
}
The code above generates the following result.