当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ZonedDateTime getDayOfWeek()用法及代码示例


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()



相关用法


注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 ZonedDateTime getDayOfWeek() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。