Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class Main {
    private static String setDate(int day, Locale locale) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, +day);
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        if (df instanceof SimpleDateFormat) {
            SimpleDateFormat sdf = (SimpleDateFormat) df;
            // To show Locale specific short date expression with full year
            String pattern = sdf.toPattern().replaceAll("y+", "yyyy");
            sdf.applyPattern(pattern);
            return sdf.format(cal.getTime());
        }
        String formattedDate = df.format(cal.getTime());
        return formattedDate;
    }

    public static void main(String[] args) {
        System.out.println(setDate(1, Locale.JAPAN));
    }
}