Java 8 Period - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Period class.

This code example shows how to use the following methods:getDays, getMonths, getYears, isZero
     * @return the amount of time in ISO8601 string format 
     */ 
    public String toString(Period value) {
 
        final String str;
        if (value.isZero()) {
            str = "PT0S";
        } else { 
            StringBuilder buf = new StringBuilder();
            buf.append('P');
            if (value.getYears() != 0) {
                buf.append(value.getYears()).append('Y');
            } 
            if (value.getMonths() != 0) {
                buf.append(value.getMonths()).append('M');
            } 
            if (value.getDays() != 0) {
                buf.append(value.getDays()).append('D');
            } 
            str = buf.toString();

6
CodeRank
This code example shows how to use the following methods:getDays, getMonths, getYears
		Period diff = Period.between(endofCentury, now);
		 
		System.out.printf("The 21st century (up to %s) is %s old%n", now, diff);
		System.out.printf(
				"The 21st century is %d years, %d months and %d days old", 
				diff.getYears(), diff.getMonths(), diff.getDays());
	} 
} 
// END main 
5
CodeRank
See Code Examples for Java 8 Period Methods: