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


Java WeekFields toString()用法及代碼示例


WeekFields類的toString()方法用於返回此WeekFields對象的字符串表示形式。

用法:

public String toString()

參數:此方法不接受任何內容。


返回值:此方法返回此WeekFields的字符串表示形式。

以下示例程序旨在說明WeekFields.toString()方法:
程序1:

// Java program to demonstrate 
// WeekFields.toString() method 
  
import java.time.DayOfWeek; 
import java.time.temporal.WeekFields; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create WeekFields 
        WeekFields weekFields 
            = WeekFields.of(DayOfWeek.MONDAY, 1); 
  
        // apply toString() 
        String toString = weekFields.toString(); 
  
        // print results 
        System.out.println("String representation:"
                           + toString); 
    } 
}
輸出:
String representation:WeekFields[MONDAY, 1]

程序2:

// Java program to demonstrate 
// WeekFields.toString() method 
  
import java.time.temporal.WeekFields; 
import java.util.Locale; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        Locale locale = new Locale("EN", "INDIA"); 
  
        // create WeekFields 
        WeekFields weekFields = WeekFields.of(locale); 
  
        // apply toString() 
        String toString = weekFields.toString(); 
  
        // print results 
        System.out.println("String representation:"
                           + toString); 
    } 
}
輸出:
String representation:WeekFields[SUNDAY, 1]

參考:https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#toString()



相關用法


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