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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。