Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Main {

    public static void main(String[] args) {
        System.out.println(getDateAsStringIncrementedByYear("04/22/1980 11:30:20", "MM/dd/yyyy HH:mm:ss", 1));
    }

    private static String getDateAsStringIncrementedByYear(String inputDateStr, String pattern,
            long yearsToIncrement) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        LocalDateTime dateTime = LocalDateTime.parse(inputDateStr, formatter);
        return dateTime.plusYears(yearsToIncrement).format(formatter);
    }
}