📌  相关文章
📜  Java中的 ZonedDateTime getDayOfWeek() 方法及示例

📅  最后修改于: 2022-05-13 01:55:28.945000             🧑  作者: Mango

Java中的 ZonedDateTime getDayOfWeek() 方法及示例

ZonedDateTime类的getDayOfWeek()方法用于从这个ZonedDateTime 中获取星期几字段,它是一个枚举DayOfWeek。可以从DayOfWeek 中获取更多信息。这包括值的文本名称。

句法:

public DayOfWeek getDayOfWeek()

参数:此方法不带任何参数。

返回值:此方法返回表示星期几的枚举DayOfWeek

下面的程序说明了 getDayOfWeek() 方法:

方案一:

// 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

方案二:

// 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: Java/time/ZonedDateTime.html#getDayOfWeek()