Get day of week in Java
Description
The following code shows how to get day of week.
Example
/*from www . j ava 2s .c om*/
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2007);
calendar.set(Calendar.DAY_OF_YEAR, 180);
// See the full information of the calendar object.
System.out.println(calendar.getTime().toString());
// Get the weekday and print it
int weekday = calendar.get(Calendar.DAY_OF_WEEK);
System.out.println("Weekday: " + weekday);
}
}
The code above generates the following result.