Close

Java Date Time - Year.parse() Examples

Java Date Time Java Java API 


Class:

java.time.Year

java.lang.Objectjava.lang.Objectjava.time.Yearjava.time.Yearjava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Methods:

public static Year parse(CharSequence text)

Obtains an instance of Year from a text string in 'yyyy' format.



public static Year parse(CharSequence text,
                         DateTimeFormatter formatter)

Obtains an instance of Year from a text string using a specific formatter.


Examples


package com.logicbig.example.year;

import java.time.Year;

public class ParseExample {

public static void main(String... args) {
Year y = Year.parse("2010");
System.out.println(y);
}
}

Output

2010




package com.logicbig.example.year;

import java.time.Year;
import java.time.format.DateTimeFormatter;

public class ParseExample2 {

public static void main(String... args) {
DateTimeFormatter f = DateTimeFormatter.ofPattern("yy");
System.out.println(f);

Year y = Year.parse("10", f);
System.out.println(y);
}
}

Output

ReducedValue(YearOfEra,2,2,2000-01-01)
2010




See Also