Java中的OffsetDateTime类的getDayOfWeek()方法获取day-of-month字段。
用法:
public int getDayOfMonth()
参数:此方法接受不接受任何参数。
返回值:它返回day-of-month,它可以是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
程序2:
// 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