當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java OffsetDateTime getDayOfWeek()用法及代碼示例


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–



相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetDateTime getDayOfWeek() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。