ZonedDateTime类的getDayOfWeek()方法用于从此ZonedDateTime获取day-of-week字段,该字段是枚举DayOfWeek。可以从DayOfWeek获取其他信息。这包括值的文本名称。
用法:
public DayOfWeek getDayOfWeek()
参数:此方法不带任何参数。
返回值:此方法返回代表day-of-week的枚举DayOfWeek。
以下示例程序旨在说明getDayOfWeek()方法:
示例1:
// Java program to demonstrate
// ZonedDateTime.getDayOfWeek() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a ZonedDateTime object
ZonedDateTime zoneddatetime
= ZonedDateTime.parse(
"2018-12-06T19:21:12.123+05:30[Asia/Calcutta]");
// get day-of-week field
DayOfWeek value = zoneddatetime.getDayOfWeek();
// print result
System.out.println("day-of-week:" + value);
}
}
输出:
day-of-week:THURSDAY
示例2:
// Java program to demonstrate
// ZonedDateTime.getDayOfWeek() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a ZonedDateTime object
ZonedDateTime zoneddatetime
= ZonedDateTime.parse(
"2018-10-24T23:12:31.123+02:00[Europe/Paris]");
// get day-of-week field
DayOfWeek value = zoneddatetime.getDayOfWeek();
// print result
System.out.println("day-of-week:" + value);
}
}
输出:
day-of-week:WEDNESDAY
参考: https://docs.oracle.com/javase/10/docs/api/java/time/ZonedDateTime.html#getDayOfWeek()
相关用法
- Java OffsetDateTime getDayOfWeek()用法及代码示例
- Java LocalDateTime getDayOfWeek()用法及代码示例
- Java ZonedDateTime of()用法及代码示例
- Java ZonedDateTime get()用法及代码示例
- Java ZonedDateTime plus()用法及代码示例
- Java ZonedDateTime until()用法及代码示例
- Java ZonedDateTime with()用法及代码示例
- Java ZonedDateTime now()用法及代码示例
- Java ZonedDateTime withZoneSameLocal()用法及代码示例
- Java ZonedDateTime withZoneSameInstant()用法及代码示例
- Java ZonedDateTime minusMinutes()用法及代码示例
- Java ZonedDateTime withFixedOffsetZone()用法及代码示例
- Java ZonedDateTime plusMonths()用法及代码示例
- Java ZonedDateTime withEarlierOffsetAtOverlap()用法及代码示例
- Java ZonedDateTime toLocalDateTime()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 ZonedDateTime getDayOfWeek() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。