Java ZonedDateTime getDayOfWeek()方法及示例
ZonedDateTime 类的 getDayOfWeek() 方法用于从这个ZonedDateTime中获取星期字段,它是一个枚举DayOfWeek.可以从DayOfWeek中获取其他信息。这包括数值的文本名称。
语法
public DayOfWeek getDayOfWeek()
参数: 该方法不接受任何参数。
返回值: 该方法返回一个代表星期天的枚举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()