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 getCurrentDateString() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR) + "-" + String.format("%02d", (calendar.get(Calendar.MONTH) + 1)) + "-"
                + String.format("%02d", calendar.get(Calendar.DATE));
    }

    public static String getCurrentDateString(Calendar calendar) {
        if (calendar == null)
            return "";
        return calendar.get(Calendar.YEAR) + "-" + String.format("%02d", (calendar.get(Calendar.MONTH) + 1)) + "-"
                + String.format("%02d", calendar.get(Calendar.DATE));
    }
}