Java Date Time - Year toString() example








Year toString() outputs this year as a String.

Syntax

toString has the following syntax.

public String toString()

Example

The following example shows how to use toString.

import java.time.Year;
//  w  w w  .  ja v a2s . c o m
public class Main {
  public static void main(String[] args) {
    
    Year y = Year.of(2014);

    System.out.println(y.toString());

  }
}

The code above generates the following result.