Java中LocalDate類的getDayOfWeek()方法獲取day-of-week字段,該字段是一個枚舉DayOfWeek。
用法:
public DayOfWeek getDayOfWeek()
參數:此方法不接受任何參數。
返回值:該函數返回星期幾,而不是null。
以下示例程序旨在說明Java中LocalDate的getDayOfWeek()方法:
程序1:
// Program to illustrate the getDayOfWeek() method
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
// Parses the date
LocalDate dt = LocalDate.parse("2018-11-27");
// Prints the day
System.out.println(dt.getDayOfWeek());
}
}
輸出:
TUESDAY
程序2:
// Program to illustrate the getDayOfWeek() method
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
// Parses the date
LocalDate dt = LocalDate.parse("2018-01-09");
// Prints the day
System.out.println(dt.getDayOfWeek());
}
}
輸出:
TUESDAY