I wish to remove the Joda-Time library from my project.
I am trying to convert a two digit year to full year. The following code from Joda-Time can fulfil the purpos
You could parse the year directly using formatter.parse(input, Year::from)
:
import java.time.*;
import java.time.format.*;
class Main {
public static void main(String[] args) {
DateTimeFormatter TWO_YEAR_FORMATTER = DateTimeFormatter.ofPattern("yy");
Year year = TWO_YEAR_FORMATTER.parse("99", Year::from);
System.out.println(year);
}
}
Note that this will output 2099
. To output 1999, you should use a specific formatter like the one suggested by Ole V.V. in their answer.