Period toString() example
Description
Period toString()
outputs this period as a String, such as P6Y3M1D.
The output will be in the ISO-8601 period format.
A zero period will be represented as zero days, 'P0D'.
Syntax
toString
has the following syntax.
public String toString()
Example
The following example shows how to use toString
.
import java.time.Period;
/* w ww. j av a2s. com*/
public class Main {
public static void main(String[] args) {
Period p = Period.ofDays(12);
System.out.println(p.toString());
}
}
The code above generates the following result.