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
參考: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#getDayOfWeek()
相關用法
- Java LocalDateTime getDayOfWeek()用法及代碼示例
- Java OffsetDateTime getDayOfWeek()用法及代碼示例
- Java ZonedDateTime getDayOfWeek()用法及代碼示例
- Java LocalDate from()用法及代碼示例
- Java LocalDate now()用法及代碼示例
- Java LocalDate plus()用法及代碼示例
- Java LocalDate with()用法及代碼示例
- Java LocalDate now()用法及代碼示例
- Java LocalDate adjustInto()用法及代碼示例
- Java LocalDate getChronology()用法及代碼示例
- Java LocalDate getDayOfMonth()用法及代碼示例
- Java LocalDate getMonth()用法及代碼示例
- Java LocalDate format()用法及代碼示例
- Java LocalDate get()用法及代碼示例
- Java LocalDate compareTo()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 LocalDate getDayOfWeek() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。