Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Calendar;

public class Main {
    public static String getTodayYYYYMMDD() {
        Calendar calendar = Calendar.getInstance();
        StringBuffer sbDate = new StringBuffer();
        int nYear, nMonth, nDay;
        nYear = calendar.get(Calendar.YEAR);
        nMonth = calendar.get(Calendar.MONTH) + 1;
        nDay = calendar.get(Calendar.DAY_OF_MONTH);
        sbDate.append(nYear);
        if (nMonth < 10)
            sbDate.append("0");
        sbDate.append(nMonth);
        if (nDay < 10)
            sbDate.append("0");
        sbDate.append(nDay);

        return sbDate.toString();
    }
}