Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.*;

public class Main {

    @SuppressWarnings("deprecation")
    public static String changeDateAsMonth(String date, int imonth) {
        GregorianCalendar calendar = new GregorianCalendar();
        if (date.length() == 8) {
            calendar.set(Integer.parseInt(date.substring(0, 4)), Integer.parseInt(date.substring(4, 6)) - 1,
                    Integer.parseInt(date.substring(6, 8)));
        } else if (date.length() == 10) {
            calendar.set(Integer.parseInt(date.substring(0, 4)), Integer.parseInt(date.substring(5, 7)) - 1,
                    Integer.parseInt(date.substring(8, 10)));
        }
        calendar.add(GregorianCalendar.MONTH, imonth);
        String sDate[] = calendar.getTime().toLocaleString().split(" ");
        return sDate[0];
    }
}