Java中的 OffsetDateTime getDayOfWeek() 方法及示例
Java中 OffsetDateTime 类的getDayOfWeek()方法获取日期字段。
句法 :
public int getDayOfMonth()
参数:此方法接受不接受任何参数。
返回值:返回日期,范围为 1 到 31。
下面的程序说明了getDayOfWeek()方法:
程序 1:
// Java program to demonstrate the getDayOfWeek() method
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
// parses a date
OffsetDateTime date = OffsetDateTime.parse("2018-12-03T12:30:30+01:00");
// Prints the day of week of given date
System.out.println("day: " + date.getDayOfWeek());
}
}
输出:
day: MONDAY
方案二:
// Java program to demonstrate the getDayOfWeek() method
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
// parses a date
OffsetDateTime date = OffsetDateTime.parse("2018-12-31T12:30:30+01:00");
// Prints the day of week of given date
System.out.println("Day: " + date.getDayOfWeek());
}
}
输出:
Day: MONDAY
参考:https: Java/time/OffsetDateTime.html#getDayOfWeek–