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
参考: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html#getDayOfWeek–
相关用法
- Java LocalDateTime getDayOfWeek()用法及代码示例
- Java ZonedDateTime getDayOfWeek()用法及代码示例
- Java OffsetDateTime get()用法及代码示例
- Java OffsetDateTime until()用法及代码示例
- Java OffsetDateTime from()用法及代码示例
- Java OffsetDateTime with()用法及代码示例
- Java OffsetDateTime minusMonths()用法及代码示例
- Java OffsetDateTime isAfter()用法及代码示例
- Java OffsetDateTime withDayOfMonth()用法及代码示例
- Java OffsetDateTime withNano()用法及代码示例
- Java OffsetDateTime withHour()用法及代码示例
- Java OffsetDateTime minusDays()用法及代码示例
- Java OffsetDateTime minusMinutes()用法及代码示例
- Java OffsetDateTime getOffset()用法及代码示例
- Java OffsetDateTime withYear()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 OffsetDateTime getDayOfWeek() method in Java with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。